diff options
author | Guangxiong Lin <[email protected]> | 2022-01-22 21:11:52 +0800 |
---|---|---|
committer | Guangxiong Lin <[email protected]> | 2022-01-22 21:11:52 +0800 |
commit | 843b8510acd58fa9c1d1df6d8837d0406392e1b2 (patch) | |
tree | 1a4cf0c23b8100dad12a822238f8e4ee4a0fc7d2 | |
parent | 2a73c0e9167373828763e1965fc6fedda9431509 (diff) | |
download | dotfiles-843b8510acd58fa9c1d1df6d8837d0406392e1b2.tar.gz dotfiles-843b8510acd58fa9c1d1df6d8837d0406392e1b2.tar.bz2 dotfiles-843b8510acd58fa9c1d1df6d8837d0406392e1b2.zip |
Add fzf config
The fzf config is splited into .env and .functions before. It will be
hard to remove the config of fzf when I want to replace fzf with other
finder (e.g. skim). I place all config related to .fzfrc now.
Besides, I add the config to load fzf completion and key bindings.
-rw-r--r-- | .env | 5 | ||||
-rw-r--r-- | .functions | 32 | ||||
-rwxr-xr-x | .fzfrc | 62 | ||||
-rw-r--r-- | .zshrc | 1 | ||||
-rwxr-xr-x | scripts/bootstrap.sh | 2 |
5 files changed, 64 insertions, 38 deletions
@@ -10,11 +10,6 @@ export TERMINAL=$TERMINAL [ -f /usr/share/z/z.sh -o -f /usr/local/etc/profile.d/z.sh ] && export _Z_CMD='j' -export FZF_DEFAULT_COMMAND='find . -type f' -if [ -f /usr/bin/fd ];then - export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git' -fi - if type fcitx5 > /dev/null; then export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx @@ -1,37 +1,5 @@ #!/usr/bin/env bash -fco () { - local tags branches target - branches=$( - git --no-pager branch --all \ - --format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \ - | sed '/^$/d' - ) || return - tags=$( - git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}' - ) || return - target=$( - (echo $branches; echo $tags) \ - | fzf --no-hscroll --no-multi -n 2 --ansi - ) || return - git checkout $(awk '{print $2}' <<<$target) -} - -fs () { - local session - session=$(tmux list-sessions -F "#{session_name}" \ - | fzf --query=$1 --select-1 --exit-0) \ - && tmux switch-client -t $session -} - -tm() { - [[ -n "$TMUX" ]] && change="switch-client" || change="attach-session" - if [ $1 ]; then - tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return - fi - session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found." -} - open () { if [ -f /usr/bin/xdg-open ]; then nohup xdg-open "$*" > /dev/null 2>&1 & @@ -0,0 +1,62 @@ +# vim: ft=sh + +export FZF_DEFAULT_COMMAND='find . -type f' +if [ -f /usr/bin/fd ];then + export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git' +fi + +# completion and key bindings + +case $SHELL in +*/zsh) + complete_share_file=/usr/share/fzf/completion.zsh + keybinds_share_file=/usr/share/fzf/key-bindings.zsh + + [ -f $complete_share_file ] && source $complete_share_file + [ -f $keybinds_share_file ] && source $keybinds_share_file + + complete_local_file=/usr/local/opt/fzf/shell/completion.zsh + keybinds_local_file=/usr/local/opt/fzf/shell/key-bindings.zsh + + [ -f $complete_local_file ] && source $complete_local_file + [ -f $keybinds_local_file ] && source $keybinds_local_file + ;; +*/bash) + ;; +*) +esac + +# functions + +fco () { + local tags branches target + branches=$( + git --no-pager branch --all \ + --format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \ + | sed '/^$/d' + ) || return + tags=$( + git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}' + ) || return + target=$( + (echo $branches; echo $tags) \ + | fzf --no-hscroll --no-multi -n 2 --ansi + ) || return + git checkout $(awk '{print $2}' <<<$target) +} + +fs () { + local session + session=$(tmux list-sessions -F "#{session_name}" \ + | fzf --query=$1 --select-1 --exit-0) \ + && tmux switch-client -t $session +} + +tm() { + [[ -n "$TMUX" ]] && change="switch-client" || change="attach-session" + if [ $1 ]; then + tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return + fi + session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found." +} + @@ -64,3 +64,4 @@ source $HOME/.functions [ -f $HOME/.zsh_local ] && source $HOME/.zsh_local [ -f $HOME/.nnnrc ] && source $HOME/.nnnrc +[ -f $HOME/.fzfrc ] && source $HOME/.fzfrc diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 235aead..dc5d3cc 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -21,7 +21,7 @@ link_all () { .mbsyncrc .msmtprc .tmux.conf .urlview .zshrc \ .vimrc .vim .path .functions .emacs.d .gitconfig \ .config/i3 .config/polybar .xinitrc .pam_environment \ - .zprofile .newsboat .ledgerrc .nnnrc .alacritty.yml + .zprofile .newsboat .ledgerrc .nnnrc .alacritty.yml .fzfrc } main () { |