aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--alias7
-rwxr-xr-xtools/init/load-settings.sh3
-rw-r--r--zsh/_hugo177
4 files changed, 183 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index cf6e58e..f86960f 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ tig:
15vim: 15vim:
16 # amix-vimrc 16 # amix-vimrc
17 if [ ! -d "$(HOME)/.vim_runtime" ]; then 17 if [ ! -d "$(HOME)/.vim_runtime" ]; then
18 git clone --depth=1 --origin my git@github.com:amix/vimrc.git ~/.vim_runtime && 18 git clone --depth=1 --origin my https://github.com/amix/vimrc ~/.vim_runtime &&
19 cd ~/.vim_runtime && sh ~/.vim_runtime/install_awesome_vimrc.sh 19 cd ~/.vim_runtime && sh ~/.vim_runtime/install_awesome_vimrc.sh
20 fi 20 fi
21 # vim-plug 21 # vim-plug
diff --git a/alias b/alias
index a4ce0b3..50f994f 100644
--- a/alias
+++ b/alias
@@ -422,8 +422,11 @@ tt() {
422 422
423# upload with 0x0.st 423# upload with 0x0.st
424up() { 424up() {
425 #curl -F"file=@${1}" http://0x0.st 425 curl -F"file=@${1}" http://0x0.st
426 curl -F "file=@${1}" https://api.anonfiles.com/upload 426 #curl -F "file=@${1}" https://api.anonfiles.com/upload
427}
428sshup() {
429 scp "$1" topo:~/public
427} 430}
428short() { 431short() {
429 curl -F"shorten=${1}" http://0x0.st 432 curl -F"shorten=${1}" http://0x0.st
diff --git a/tools/init/load-settings.sh b/tools/init/load-settings.sh
index 779ef45..68844c1 100755
--- a/tools/init/load-settings.sh
+++ b/tools/init/load-settings.sh
@@ -5,9 +5,6 @@ export EDITOR=vim
5source $SETTING_DIR/alias 5source $SETTING_DIR/alias
6[[ -d $SETTING_DIR/private ]] && for f in $SETTING_DIR/private/*; do source $f; done 6[[ -d $SETTING_DIR/private ]] && for f in $SETTING_DIR/private/*; do source $f; done
7 7
8# set caps as ctrl under X
9setxkbmap -option ctrl:nocaps 2>/dev/null
10
11# Config shell 8# Config shell
12shell=$(cat /proc/$$/cmdline | tr -d '\0') 9shell=$(cat /proc/$$/cmdline | tr -d '\0')
13case $shell in 10case $shell in
diff --git a/zsh/_hugo b/zsh/_hugo
new file mode 100644
index 0000000..b6ada8d
--- /dev/null
+++ b/zsh/_hugo
@@ -0,0 +1,177 @@
1#compdef _hugo hugo
2
3# zsh completion for hugo -*- shell-script -*-
4
5__hugo_debug()
6{
7 local file="$BASH_COMP_DEBUG_FILE"
8 if [[ -n ${file} ]]; then
9 echo "$*" >> "${file}"
10 fi
11}
12
13_hugo()
14{
15 local shellCompDirectiveError=1
16 local shellCompDirectiveNoSpace=2
17 local shellCompDirectiveNoFileComp=4
18 local shellCompDirectiveFilterFileExt=8
19 local shellCompDirectiveFilterDirs=16
20
21 local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace
22 local -a completions
23
24 __hugo_debug "\n========= starting completion logic =========="
25 __hugo_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}"
26
27 # The user could have moved the cursor backwards on the command-line.
28 # We need to trigger completion from the $CURRENT location, so we need
29 # to truncate the command-line ($words) up to the $CURRENT location.
30 # (We cannot use $CURSOR as its value does not work when a command is an alias.)
31 words=("${=words[1,CURRENT]}")
32 __hugo_debug "Truncated words[*]: ${words[*]},"
33
34 lastParam=${words[-1]}
35 lastChar=${lastParam[-1]}
36 __hugo_debug "lastParam: ${lastParam}, lastChar: ${lastChar}"
37
38 # For zsh, when completing a flag with an = (e.g., hugo -n=<TAB>)
39 # completions must be prefixed with the flag
40 setopt local_options BASH_REMATCH
41 if [[ "${lastParam}" =~ '-.*=' ]]; then
42 # We are dealing with a flag with an =
43 flagPrefix="-P ${BASH_REMATCH}"
44 fi
45
46 # Prepare the command to obtain completions
47 requestComp="${words[1]} __complete ${words[2,-1]}"
48 if [ "${lastChar}" = "" ]; then
49 # If the last parameter is complete (there is a space following it)
50 # We add an extra empty parameter so we can indicate this to the go completion code.
51 __hugo_debug "Adding extra empty parameter"
52 requestComp="${requestComp} \"\""
53 fi
54
55 __hugo_debug "About to call: eval ${requestComp}"
56
57 # Use eval to handle any environment variables and such
58 out=$(eval ${requestComp} 2>/dev/null)
59 __hugo_debug "completion output: ${out}"
60
61 # Extract the directive integer following a : from the last line
62 local lastLine
63 while IFS='\n' read -r line; do
64 lastLine=${line}
65 done < <(printf "%s\n" "${out[@]}")
66 __hugo_debug "last line: ${lastLine}"
67
68 if [ "${lastLine[1]}" = : ]; then
69 directive=${lastLine[2,-1]}
70 # Remove the directive including the : and the newline
71 local suffix
72 (( suffix=${#lastLine}+2))
73 out=${out[1,-$suffix]}
74 else
75 # There is no directive specified. Leave $out as is.
76 __hugo_debug "No directive found. Setting do default"
77 directive=0
78 fi
79
80 __hugo_debug "directive: ${directive}"
81 __hugo_debug "completions: ${out}"
82 __hugo_debug "flagPrefix: ${flagPrefix}"
83
84 if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
85 __hugo_debug "Completion received error. Ignoring completions."
86 return
87 fi
88
89 while IFS='\n' read -r comp; do
90 if [ -n "$comp" ]; then
91 # If requested, completions are returned with a description.
92 # The description is preceded by a TAB character.
93 # For zsh's _describe, we need to use a : instead of a TAB.
94 # We first need to escape any : as part of the completion itself.
95 comp=${comp//:/\\:}
96
97 local tab=$(printf '\t')
98 comp=${comp//$tab/:}
99
100 __hugo_debug "Adding completion: ${comp}"
101 completions+=${comp}
102 lastComp=$comp
103 fi
104 done < <(printf "%s\n" "${out[@]}")
105
106 if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
107 __hugo_debug "Activating nospace."
108 noSpace="-S ''"
109 fi
110
111 if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
112 # File extension filtering
113 local filteringCmd
114 filteringCmd='_files'
115 for filter in ${completions[@]}; do
116 if [ ${filter[1]} != '*' ]; then
117 # zsh requires a glob pattern to do file filtering
118 filter="\*.$filter"
119 fi
120 filteringCmd+=" -g $filter"
121 done
122 filteringCmd+=" ${flagPrefix}"
123
124 __hugo_debug "File filtering command: $filteringCmd"
125 _arguments '*:filename:'"$filteringCmd"
126 elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
127 # File completion for directories only
128 local subDir
129 subdir="${completions[1]}"
130 if [ -n "$subdir" ]; then
131 __hugo_debug "Listing directories in $subdir"
132 pushd "${subdir}" >/dev/null 2>&1
133 else
134 __hugo_debug "Listing directories in ."
135 fi
136
137 local result
138 _arguments '*:dirname:_files -/'" ${flagPrefix}"
139 result=$?
140 if [ -n "$subdir" ]; then
141 popd >/dev/null 2>&1
142 fi
143 return $result
144 else
145 __hugo_debug "Calling _describe"
146 if eval _describe "completions" completions $flagPrefix $noSpace; then
147 __hugo_debug "_describe found some completions"
148
149 # Return the success of having called _describe
150 return 0
151 else
152 __hugo_debug "_describe did not find completions."
153 __hugo_debug "Checking if we should do file completion."
154 if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
155 __hugo_debug "deactivating file completion"
156
157 # We must return an error code here to let zsh know that there were no
158 # completions found by _describe; this is what will trigger other
159 # matching algorithms to attempt to find completions.
160 # For example zsh can match letters in the middle of words.
161 return 1
162 else
163 # Perform file completion
164 __hugo_debug "Activating file completion"
165
166 # We must return the result of this command, so it must be the
167 # last command, or else we must store its result to return it.
168 _arguments '*:filename:_files'" ${flagPrefix}"
169 fi
170 fi
171 fi
172}
173
174# don't run the completion function when being source-ed or eval-ed
175if [ "$funcstack[1]" = "_hugo" ]; then
176 _hugo
177fi