[zsh] 集成 zsh 配置
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
# Complete filename by modification time
|
||||
zstyle ':completion:*' file-sort modification
|
||||
|
||||
# FZF shell integration
|
||||
source <(fzf --zsh)
|
||||
|
||||
if command -v bat &> /dev/null; then
|
||||
# Preview file content using bat (https://github.com/sharkdp/bat)
|
||||
export FZF_CTRL_T_OPTS="
|
||||
--walker-skip .git,node_modules,target
|
||||
--preview 'bat -n --color=always {}'
|
||||
--bind 'ctrl-/:change-preview-window(down|hidden|)'"
|
||||
fi
|
||||
if command -v tree &> /dev/null; then
|
||||
# Preview directory tree using tree
|
||||
export FZF_ALT_C_OPTS="
|
||||
--walker-skip .git,node_modules,target
|
||||
--preview 'tree -C {} | head -200'"
|
||||
fi
|
||||
|
||||
# FZF Fuzzy completion
|
||||
export FZF_COMPLETION_TRIGGER=''
|
||||
bindkey -r '^P'
|
||||
bindkey -r '^I'
|
||||
bindkey '^P' fzf-completion
|
||||
bindkey '^I' $fzf_default_completion
|
||||
|
||||
# Options to fzf command
|
||||
export FZF_COMPLETION_OPTS='--border --info=inline'
|
||||
|
||||
if command -v fd &> /dev/null; then
|
||||
# Use fd (https://github.com/sharkdp/fd) for listing path candidates.
|
||||
# - The first argument to the function ($1) is the base path to start traversal
|
||||
# - See the source code (completion.{bash,zsh}) for the details.
|
||||
_fzf_compgen_path() {
|
||||
fd --hidden --follow --exclude ".git" . "$1"
|
||||
}
|
||||
# Use fd to generate the list for directory completion
|
||||
_fzf_compgen_dir() {
|
||||
fd --type d --hidden --follow --exclude ".git" . "$1"
|
||||
}
|
||||
fi
|
||||
|
||||
|
||||
# Advanced customization of fzf options via _fzf_comprun function
|
||||
# - The first argument to the function is the name of the command.
|
||||
# - You should make sure to pass the rest of the arguments to fzf.
|
||||
_fzf_comprun() {
|
||||
local command=$1
|
||||
shift
|
||||
|
||||
case "$command" in
|
||||
cd) fzf --preview 'tree -C {} | head -200' "$@" ;;
|
||||
export|unset) fzf --preview "eval 'echo \$'{}" "$@" ;;
|
||||
ssh) fzf --preview 'dig {}' "$@" ;;
|
||||
*) fzf --preview 'bat -n --color=always {}' "$@" ;;
|
||||
esac
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
cmake-llvm () {
|
||||
local cmake_args=("-G" "Ninja")
|
||||
|
||||
# find cmake root dir
|
||||
# if defined PROJECT or P, use it as project root
|
||||
# if within git (git rev-parse --is-inside-work-tree), use git rev-parse --show-toplevel
|
||||
# if setted LLVM_ROOT, use it
|
||||
# default "../llvm", if not exist, error
|
||||
local llvm_root=".."
|
||||
if [ -n "${PROJECT}" ]; then
|
||||
llvm_root="${PROJECT}"
|
||||
elif [ -n "${P}" ]; then
|
||||
llvm_root="${P}"
|
||||
elif git rev-parse --is-inside-work-tree &> /dev/null; then
|
||||
llvm_root=$(git rev-parse --show-toplevel)
|
||||
elif [ -n "${LLVM_ROOT}" ]; then
|
||||
llvm_root="${LLVM_ROOT}"
|
||||
fi
|
||||
if [ ! -d "${llvm_root}/llvm" ]; then
|
||||
echo "Error: not inside a llvm directory"
|
||||
return 1
|
||||
fi
|
||||
cmake_args+=("${llvm_root}/llvm")
|
||||
|
||||
# Set build_type from arg[1]
|
||||
local build_type="${1}"
|
||||
if [ -z "${build_type}" ]; then
|
||||
echo "Error: build_type is empty"
|
||||
return 1
|
||||
fi
|
||||
cmake_args+=("-DCMAKE_BUILD_TYPE=${build_type}")
|
||||
|
||||
# check LLVM_PROJECTS env
|
||||
if [ -z "${LLVM_PROJECTS}" ]; then
|
||||
echo "Error: LLVM_PROJECTS env is not set"
|
||||
return 1
|
||||
fi
|
||||
cmake_args+=("-DLLVM_ENABLE_PROJECTS=${LLVM_PROJECTS}")
|
||||
|
||||
# check LLVM_TARGETS
|
||||
if [ -z "${LLVM_TARGETS}" ]; then
|
||||
echo "Error: LLVM_TARGETS env is not set"
|
||||
return 1
|
||||
fi
|
||||
cmake_args+=("-DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS}")
|
||||
|
||||
# if setted LLVM_COMPILER, use it, else default clang
|
||||
if [ -z "${LLVM_COMPILER}" ]; then
|
||||
# if setted CMAKE_C_COMPILER or CMAKE_CXX_COMPILER, use it, else default clang
|
||||
cmake_args+=(
|
||||
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER:-clang}"
|
||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER:-clang++}"
|
||||
)
|
||||
elif [ "${LLVM_COMPILER}" == "gcc" ]; then
|
||||
cmake_args+=("-DCMAKE_C_COMPILER=gcc" "-DCMAKE_CXX_COMPILER=g++")
|
||||
elif [ "${LLVM_COMPILER}" == "clang" ]; then
|
||||
cmake_args+=("-DCMAKE_C_COMPILER=clang" "-DCMAKE_CXX_COMPILER=clang++")
|
||||
else
|
||||
echo "Error: LLVM_COMPILER is invalid"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# if not setted LLVM_NO_*, use default optimized options
|
||||
if [ -z "${LLVM_NO_SHARED}" ]; then
|
||||
cmake_args+=("-DBUILD_SHARED_LIBS=On")
|
||||
fi
|
||||
if [ -z "${LLVM_APPEND_VC_REV}"]; then
|
||||
cmake_args+=("-DLLVM_APPEND_VC_REV=Off")
|
||||
fi
|
||||
if [ -z "${LLVM_NO_LLD}" ]; then
|
||||
cmake_args+=("-DLLVM_ENABLE_LLD=On")
|
||||
fi
|
||||
if [ -z "${LLVM_NO_OPT_TABLEGEN}" ]; then
|
||||
cmake_args+=("-DLLVM_OPTIMIZED_TABLEGEN=On")
|
||||
fi
|
||||
if [ -z "${LLVM_NO_SPLIT_DWARF}" ]; then
|
||||
cmake_args+=("-DLLVM_USE_SPLIT_DWARF=On")
|
||||
fi
|
||||
|
||||
cmake_args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS=On")
|
||||
|
||||
# append args[2:] to cmake_args
|
||||
cmake_args+=("${@:2}")
|
||||
|
||||
# print cmake args, one for each line
|
||||
# and ask for confirmation
|
||||
for arg in "${cmake_args[@]}"; do
|
||||
echo "${arg}"
|
||||
done
|
||||
read "?Press enter to continue?"
|
||||
|
||||
# run cmake with cmake_args
|
||||
cmake "${cmake_args[@]}"
|
||||
}
|
||||
|
||||
git-local-exclude () {
|
||||
local file="${1}"
|
||||
|
||||
# if file is empty, exit
|
||||
if [ -z "${file}" ]; then
|
||||
echo "Error: file is empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# if .git/info/exclude not exist, exit
|
||||
if [ ! -f .git/info/exclude ]; then
|
||||
echo "warning: .git/info/exclude not exist, maybe in other worktree?"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "${file}" >> .git/info/exclude
|
||||
}
|
||||
|
||||
generate-local-dir () {
|
||||
if git rev-parse --is-inside-work-tree &> /dev/null; then
|
||||
project_root=$(git rev-parse --show-toplevel)
|
||||
else
|
||||
echo "Error: not inside a git repository"
|
||||
return 1
|
||||
fi
|
||||
|
||||
pushd "${project_root}"
|
||||
git-local-exclude .local
|
||||
mkdir -p .local
|
||||
mkdir -p .local/bin
|
||||
touch .local/notes.md
|
||||
|
||||
cat > .local/env.sh << EOF
|
||||
export P="${project_root}"
|
||||
export D="\$P/build-debug/bin"
|
||||
export R="\$P/build-release/bin"
|
||||
export L="\$P/.local"
|
||||
|
||||
export PATH="\$L/bin:\$PATH"
|
||||
EOF
|
||||
|
||||
git-local-exclude .vscode
|
||||
mkdir -p .vscode
|
||||
if [ -f .vscode/settings.json ]; then
|
||||
echo "Warning: .vscode/settings.json already exist"
|
||||
else
|
||||
echo '{}' > .vscode/settings.json
|
||||
fi
|
||||
|
||||
popd
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
# From https://serverfault.com/a/1064320
|
||||
ssh2config() {
|
||||
host="$(ssh -G "$@" | sed -n 's/^hostname //p')"
|
||||
echo "$host"
|
||||
comm -23 <(ssh -G "$@" | sort) <(ssh -G abcddd | sort) | sed 's/^/ /'
|
||||
echo ''
|
||||
}
|
||||
|
||||
backlight() {
|
||||
#echo $1 | sudo tee /sys/class/backlight/intel_backlight/brightness
|
||||
echo $1 | sudo tee /sys/class/backlight/amdgpu_bl1/brightness
|
||||
}
|
||||
|
||||
gpg-login() {
|
||||
export GPG_TTY=$(tty)
|
||||
echo "test" | gpg --clearsign > /dev/null 2>&1
|
||||
}
|
||||
|
||||
alias ipy='ipython'
|
||||
alias ts4='tailscale ip -4'
|
||||
alias ts6='tailscale ip -6'
|
||||
alias x='atool -x'
|
||||
alias pc='proxychains'
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# if bat is installed, alias cat to it
|
||||
if command -v bat &> /dev/null; then
|
||||
alias cat='bat'
|
||||
alias pcat='/usr/bin/cat'
|
||||
fi
|
||||
|
||||
# if eza is installed, alias ls to it; also check exa
|
||||
if command -v eza &> /dev/null; then
|
||||
alias ls='eza'
|
||||
elif command -v exa &> /dev/null; then
|
||||
alias ls='exa'
|
||||
fi
|
||||
alias ll='ls -l'
|
||||
alias la='ls -a'
|
||||
|
||||
# if fd is installed, alias find to it
|
||||
if command -v fd-find &> /dev/null; then
|
||||
alias fd='fd-find'
|
||||
fi
|
||||
if command -v fd &> /dev/null; then
|
||||
alias find='fd'
|
||||
fi
|
||||
|
||||
# if rg is installed, alias grep to it
|
||||
if command -v ripgrep &> /dev/null; then
|
||||
alias rg='rgrep'
|
||||
fi
|
||||
if command -v rg &> /dev/null; then
|
||||
alias grep='rg'
|
||||
fi
|
||||
|
||||
# Compatibility with windows
|
||||
alias traceroute='tracert'
|
||||
@@ -0,0 +1,29 @@
|
||||
pdf-mupdf () {
|
||||
f=$1
|
||||
mupdf $f &
|
||||
while inotifywait -e close_write $f; do
|
||||
pkill -HUP mupdf;
|
||||
done
|
||||
}
|
||||
|
||||
pdf-okular () {
|
||||
f=$1
|
||||
okular $f 2>&1 > /dev/null &
|
||||
}
|
||||
|
||||
# Open a pdf file with auto refresh
|
||||
pdf () {
|
||||
if command -v okular &> /dev/null; then
|
||||
pdf-okular "$@"
|
||||
elif command -v mupdf &> /dev/null; then
|
||||
pdf-mupdf "$@"
|
||||
else
|
||||
echo "No pdf reader found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Can't remeber the name
|
||||
gnome-pdf () {
|
||||
evince "$@" &
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# From https://wiki.archlinux.org/title/rsync
|
||||
cpr() {
|
||||
rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 "$@"
|
||||
}
|
||||
mvr() {
|
||||
rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 --remove-source-files "$@"
|
||||
}
|
||||
sudo-cpr() {
|
||||
sudo rsync -e "ssh -i $HOME/.ssh/id_ed25519 -F $HOME/.ssh/config" --archive -hh --partial --info=stats1,progress2 --modify-window=1 --remove-source-files "$@"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Created by newuser for 5.9
|
||||
|
||||
ZSHD="$HOME/.zsh.d"
|
||||
|
||||
if [[ ! -v ZSH_GRML_SOURCED ]]; then
|
||||
source $ZSHD/grml-zshrc
|
||||
fi
|
||||
|
||||
source "$ZSHD/rsync.zsh"
|
||||
source "$ZSHD/misc.zsh"
|
||||
source "$ZSHD/pdf.zsh"
|
||||
source "$ZSHD/completion.zsh"
|
||||
source "$ZSHD/modern-utils.zsh"
|
||||
source "$ZSHD/develop.zsh"
|
||||
|
||||
# allow using # at begin
|
||||
setopt interactivecomments
|
||||
# give me back the normal `#, ^, ~` !!!
|
||||
unsetopt extended_glob
|
||||
|
||||
# alias
|
||||
export EDITOR=helix
|
||||
alias edit=$EDITOR
|
||||
alias vim=helix
|
||||
alias dc="docker compose"
|
||||
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
Reference in New Issue
Block a user