Changes behaviour of ctrl t in zsh
Now pressing ctrl t will sometimes search directories if more appropriate. Pressing alt+c will now to whatever ctrl+t doesn't do if I ever need the alternative type.
This commit is contained in:
parent
08892c7fc2
commit
f2d62ffae4
1 changed files with 46 additions and 48 deletions
|
@ -2,11 +2,10 @@
|
||||||
export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --color=always --exclude .git --exclude .PlayOnLinux --exclude \"PlayOnLinux\'s virtual drives\""
|
export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --color=always --exclude .git --exclude .PlayOnLinux --exclude \"PlayOnLinux\'s virtual drives\""
|
||||||
export FZF_DEFAULT_OPTS="--reverse --ansi --height 40%"
|
export FZF_DEFAULT_OPTS="--reverse --ansi --height 40%"
|
||||||
export FZF_CTRL_R_OPTS=""
|
export FZF_CTRL_R_OPTS=""
|
||||||
# this is the argument completeion optionm, use the same command
|
export FZF_CTRL_T_OPTS="$FZF_DEFAULT_OPTS --ansi --preview \"fzf-preview {}\""
|
||||||
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
|
export FZF_ALT_C_OPTS="$FZF_DEFAULT_OPTS --ansi --preview \"fzf-preview {}\""
|
||||||
export FZF_CTRL_T_OPTS="$FZF_DEFAULT_OPTS --ansi --preview \"bat --style=numbers --color=always {}\""
|
|
||||||
#export FZF_COMPLETION_TRIGGER=''
|
|
||||||
|
|
||||||
|
# Ctrl t and alt c command are set below
|
||||||
sourced="False"
|
sourced="False"
|
||||||
|
|
||||||
if [ -e /usr/share/fzf/key-bindings.zsh ]; then
|
if [ -e /usr/share/fzf/key-bindings.zsh ]; then
|
||||||
|
@ -22,57 +21,56 @@ fi
|
||||||
|
|
||||||
if [ "$sourced" = "True" ]; then
|
if [ "$sourced" = "True" ]; then
|
||||||
|
|
||||||
|
fzf_files(){
|
||||||
# on_word_replace(){
|
# The directory can be passed as arg1
|
||||||
# setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
|
dir="${1:-$PWD}"
|
||||||
# local word="${LBUFFER##* }${RBUFFER%% *}"
|
fd --type f --hidden --follow --color=always --exclude .git --exclude .PlayOnLinux --exclude "PlayOnLinux's virtual drives" . "$dir"
|
||||||
# if [ -n "$word" ]; then
|
|
||||||
# local changeto=$(jhswap "$word" )
|
|
||||||
# local lastWord="$changeto"
|
|
||||||
# local LWORDS=$(echo $LBUFFER | tr ' ' '\n' | wc -l)
|
|
||||||
# local RWORDS=$(echo $RBUFFER | tr ' ' '\n' | wc -l)
|
|
||||||
# if [ "$LWORDS" -gt "1" ]; then
|
|
||||||
# LBUFFER="${LBUFFER% *} $lastWord"
|
|
||||||
# else
|
|
||||||
# LBUFFER="$lastWord"
|
|
||||||
# fi
|
|
||||||
# if [ "$RWORDS" -gt "1" ]; then
|
|
||||||
# RBUFFER=" ${RBUFFER#* }"
|
|
||||||
# else
|
|
||||||
# RBUFFER=""
|
|
||||||
# fi
|
|
||||||
# zle reset-prompt
|
|
||||||
# zle -R
|
|
||||||
# return 0
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# }
|
|
||||||
|
|
||||||
_fzf_complete_yay(){
|
|
||||||
local tokens=(${(z)LBUFFER})
|
|
||||||
if [ "${tokens[-1]}" = "-S" -a "${LBUFFER[-1]}" = " " ]; then
|
|
||||||
notify-send "complete"
|
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fzf_dirs(){
|
||||||
|
dir="${1:-$PWD}"
|
||||||
|
fd --type d --hidden --follow --color=always --exclude .git --exclude .PlayOnLinux --exclude "PlayOnLinux's virtual drives" . "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
# This function is used to provide the ctrl+t completion for fzf
|
||||||
|
# I find having ctrl+t for files and alt+c for directories quite jaring.
|
||||||
|
# This function will try to determine (based on the command) if it should complete files or directories.
|
||||||
|
# If it get's it wrong, alt_c will still work by doing the oposite of what it thinks
|
||||||
|
fzf_crl_t(){
|
||||||
|
local tokens cmd ret=1 lastWord oposite="${1:-false}"
|
||||||
|
# http://zsh.sourceforge.net/FAQ/zshfaq03.html
|
||||||
|
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
|
||||||
|
|
||||||
|
# Use zsh's shell parsing to split lbuffer into items
|
||||||
|
# This takes into account quoting and escaping
|
||||||
|
tokens=(${(z)LBUFFER})
|
||||||
|
|
||||||
|
|
||||||
|
# Assume the first element
|
||||||
|
# TODO: make this work for multiple commands chained with | or > or && etc.
|
||||||
|
# TODO: make this work when command prepended with variables eg a=2 foo bar
|
||||||
|
# foo is the command name
|
||||||
|
cmd="${tokens[1]}"
|
||||||
|
lastWord="${tokens[-1]}"
|
||||||
|
|
||||||
|
if [ "${LBUFFER[-1]}" != " " ]; then
|
||||||
|
current="$lastWord"
|
||||||
|
else
|
||||||
|
current="$PWD"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# An array of commands that should use dir search instead of file search
|
||||||
|
dirCommands=("cd" "find" "fd")
|
||||||
|
|
||||||
|
if [ "$oposite" = "false" ]; then
|
||||||
|
(( ${dirCommands[(I)$cmd]} )) && fzf_dirs "$current" || fzf_files "$current"
|
||||||
|
else
|
||||||
|
(( ${dirCommands[(I)$cmd]} )) && fzf_files "$current" || fzf_dirs "$current"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
export FZF_CTRL_T_COMMAND="fzf_crl_t"
|
||||||
|
export FZF_ALT_C_COMMAND="fzf_crl_t true"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue