Changes to custom tab completion

Jonathan Hodgson 5 years ago
parent e73c5e298d
commit b8f4a36858
  1. 60
      shells/zsh/oh-my-zsh-custom/fzf.zsh

@ -51,26 +51,28 @@ if [ -e /usr/share/fzf/key-bindings.zsh ]; then
jhComplete(){ jhComplete(){
local comp=$(echo $1 | cut -d':' -f1) local comp=$(echo $1 | cut -d':' -f1)
local prompt=$(echo $1 | cut -d':' -f2) local prompt=$(echo $1 | cut -d':' -f2)
local currentProject=$(project current --path)
export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --reverse --height 40%"
find "$HOME/.local/share/snippets/" -name \*.func | while read line; do
source "$line"
done
case "${comp}" in case "${comp}" in
ip) ip)
if [ -n "$currentProject" ]; then if [ -n "$currentProject" ]; then
project hosts ip --fzf project hosts ip --fzf
else
echo ""
fi fi
;; ;;
myip)
ip route | grep -oE '(dev|src) [^ ]+' | sed 'N;s/\n/,/;s/src //' | awk -F',' '{print $2 " " $1}' | sort -u | fzf --no-preview | cut -d' ' -f1
;;
pf) pf)
if [ -n "$currentProject" ]; then if [ -n "$currentProject" ]; then
find "$currentProject" -type f | fzf find "$currentProject" -type f | fzf
else
echo ""
fi fi
;; ;;
pd) pd)
if [ -n "$currentProject" ]; then if [ -n "$currentProject" ]; then
find "$currentProject" -type d | fzf --no-preview find "$currentProject" -type d | fzf --no-preview
else
echo ""
fi fi
;; ;;
wl|wordlist) wl|wordlist)
@ -79,9 +81,18 @@ if [ -e /usr/share/fzf/key-bindings.zsh ]; then
snip) snip)
snippets snippets
;; ;;
hcm)
hashcat --example-hashes | awk -v RS="\n\n" -F "\t" '{gsub("\n","\t",$0); print $1 "\t" $2 "\t" $3}' | sed 's/MODE: //; s/TYPE: //' | fzf -d "\t" --header="Mode Type" --with-nth='1,2' --preview='echo {3}' --preview-window=up:1 | cut -d' ' -f1
;;
network-interface|int)
ip -o link show | cut -d' ' -f2- | sed -E 's/[^:]+(UP|DOWN).*/\1/' | tr ':' ' ' | fzf --preview="interface=\$(echo {} | cut -f1 -d' ');ip address show \$interface" | cut -d' ' -f1
;;
*) *)
# Fall back to fzf completion if command -v "jhcomplete::$comp" > /dev/null; then
echo "" "jhcomplete::$comp"
else
echo ""
fi
esac esac
} }
@ -97,24 +108,22 @@ jhswap(){
local word="${LBUFFER##* }${RBUFFER%% *}" local word="${LBUFFER##* }${RBUFFER%% *}"
if [ -n "$word" ]; then if [ -n "$word" ]; then
local changeto=$(jhswap "$word" ) local changeto=$(jhswap "$word" )
if [ -n "$changeto" ]; then local lastWord="$changeto"
local lastWord="$changeto" local LWORDS=$(echo $LBUFFER | tr ' ' '\n' | wc -l)
local LWORDS=$(echo $LBUFFER | tr ' ' '\n' | wc -l) local RWORDS=$(echo $RBUFFER | tr ' ' '\n' | wc -l)
local RWORDS=$(echo $RBUFFER | tr ' ' '\n' | wc -l) if [ "$LWORDS" -gt "1" ]; then
if [ "$LWORDS" -gt "1" ]; then LBUFFER="${LBUFFER% *} $lastWord"
LBUFFER="${LBUFFER% *} $lastWord" else
else LBUFFER="$lastWord"
LBUFFER="$lastWord"
fi
if [ "$RWORDS" -gt "1" ]; then
RBUFFER=" ${RBUFFER#* }"
else
RBUFFER=""
fi
zle reset-prompt
zle -R
return 0
fi fi
if [ "$RWORDS" -gt "1" ]; then
RBUFFER=" ${RBUFFER#* }"
else
RBUFFER=""
fi
zle reset-prompt
zle -R
return 0
fi fi
} }
@ -142,7 +151,6 @@ jhswap(){
fi fi
cmd=${tokens[1]} cmd=${tokens[1]}
tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))} tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))}
local currentProject=$(project current --path)
#local newLBuffer="${tokens:1:${#tokens[@]}-1}" #local newLBuffer="${tokens:1:${#tokens[@]}-1}"
local newLBuffer local newLBuffer
for i in $(seq 1 $((${#tokens[@]} - 1)) ); do for i in $(seq 1 $((${#tokens[@]} - 1)) ); do

Loading…
Cancel
Save