-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.fasd-init-bash
59 lines (54 loc) · 1.62 KB
/
.fasd-init-bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
alias a='fasd -a'
alias s='fasd -si'
alias sd='fasd -sid'
alias sf='fasd -sif'
alias d='fasd -d'
alias f='fasd -f'
# function to execute built-in cd
fasd_cd() {
if [ $# -le 1 ]; then
fasd "$@"
else
local _fasd_ret="$(fasd -e 'printf %s' "$@")"
[ -z "$_fasd_ret" ] && return
[ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf %s\n "$_fasd_ret"
fi
}
alias z='fasd_cd -d'
alias zz='fasd_cd -d -i'
_fasd_prompt_func() {
eval "fasd --proc $(fasd --sanitize $(history 1 | \
sed "s/^[ ]*[0-9]*[ ]*//"))" >> "/dev/null" 2>&1
}
# add bash hook
case $PROMPT_COMMAND in
*_fasd_prompt_func*) ;;
*) PROMPT_COMMAND="$PROMPT_COMMAND;_fasd_prompt_func";;
esac
# bash command mode completion
_fasd_bash_cmd_complete() {
# complete command after "-e"
local cur=${COMP_WORDS[COMP_CWORD]}
[[ ${COMP_WORDS[COMP_CWORD-1]} == -*e ]] && \
COMPREPLY=( $(compgen -A command $cur) ) && return
# complete using default readline complete after "-A" or "-D"
case ${COMP_WORDS[COMP_CWORD-1]} in
-A|-D) COMPREPLY=( $(compgen -o default $cur) ) && return;;
esac
# get completion results using expanded aliases
local RESULT=$( fasd --complete "$(alias -p $COMP_WORDS \
2>> "/dev/null" | sed -n "\$s/^.*'\\(.*\\)'/\\1/p")
${COMP_LINE#* }" | while read -r line; do
quote_readline "$line" 2>/dev/null || \
printf %q "$line" 2>/dev/null && \
printf \\n
done)
local IFS=$'\n'; COMPREPLY=( $RESULT )
}
_fasd_bash_hook_cmd_complete() {
for cmd in $*; do
complete -F _fasd_bash_cmd_complete $cmd
done
}
# enable bash command mode completion
_fasd_bash_hook_cmd_complete fasd a s d f sd sf z zz