-
Notifications
You must be signed in to change notification settings - Fork 0
/
sh.snippets
220 lines (171 loc) · 5.03 KB
/
sh.snippets
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# vim:set ft=snippets foldclose=all foldmarker=snippet,endsnippet foldlevel=1 foldenable foldmethod=marker:
priority -51
extends sh
snippet IFS "change input file separator" b
oIFS="$IFS"; IFS=$'${1:\n}'
endsnippet
snippet "sed" "a\append i\before1 c\replaceFirstline" b
sed '/${1:[[:alnum:]]}/a \
${2:toappend}'
endsnippet
snippet "sed -n '#pa#,#pa2#p'" "print between 2 patterns"
sed -nr '#${1:<([[:alpha:]]+>)}#,#${2:</\1}/p' ./$0
endsnippet
snippet "sed 'd//'" "Delete string" b
sed -r 'd/${1:[0-9]}/' $0
endsnippet
snippet "sed 's///g'" "Replace w. String" b
sed -r 's/${1:[0-9a-zA-Z]}/${2:(\1)}/g' $0
endsnippet
snippet for "for item in ((ls))" b
for i in $( ${1:ls} ); do
echo "item: $i"
done
$0
endsnippet
snippet ifRegex "if regex" b
if [[ ${1:$string} =~ ${2:[a-zA-Z0-9]+} ]]; then
${3:echo "match in string"}
else
#regex not matched
${4:echo "no match in string"}
fi
$0
endsnippet
snippet whileRead "while read line" b
while read -r line ;do
${2:echo "$line"}
done < ${1:file}
endsnippet
snippet whileCount "while count" b
count=0
while [ $i -le ${1:10} ]; do
${echo $i}
((i+=1))
done
$0
endsnippet
snippet cat "cat > heredocument << EOF" !b
cat > ./${1:document} << EOF
${2:[catThisIntoFile]}
EOF
$0
endsnippet
# pythonInterpolatedArray snippet
global !p
def complete(t, opts):
if t:
opts = [ m[len(t):] for m in opts if m.startswith(t)]
if len(opts)==1:
return opts[0]
return "("+'|'.join(opts)+ ')'
endglobal
snippet st "Status" b
status
$0
#status $1`!p snip.rv=complete(t[1], ['new','incomplete','invalid'])`
endsnippet
# endsnippet
snippet ifBrackets "if expressionList" b
if ${1:[doing]} do;
done
$0
endsnippet
snippet if[-f] "-f file -d dir" b
if [ ${1:! -f\-d} ]; then
${2:mkdir }
fi
$0
endsnippet
snippet rename "rename files" b
rename ${1:-e} ${2:'y}/${3:[A-Z]}/${4:[a-z]}/' ${5:*.*}
$0
endsnippet
snippet rename "rename fileendings" b
rename 's/(.[A-Z]+)/lc(\$1)/ge' *.*[A-Z]*
$0
endsnippet
snippet column "-tx table -s delim" b
column -tx -s'${1:delim}'$0
endsnippet
snippet cut "cut -f field -d delim" b
cut ${1:-f1,2} ${2:-d,}$0
endsnippet
snippet "find exec" "find and exec command on files" b
find . -maxdepth 0 -empty -exec echo {} is empty. \;
endsnippet
snippet "declare -A" "Associative array[key]=value" b
${1:arrayname}[${2:key}]=${3:value}
endsnippet
snippet "varl" "string|array length" b
\$\{#${1:var[*]}\}$0
endsnippet
snippet "vars" "substitute pattern" b
\$\{${1:variable}/${2:stringToReplace}/${3:pattern}/\}$0
endsnippet
snippet "varsf" "substitute first pattern" b
\$\{${1:variable}//${2:stringToReplace}/${3:pattern}/\}$0
endsnippet
snippet "vart" "string|array trim w expand" b
\$\{${1:variable[*]}##${2:stringToTrim*}\}$0
endsnippet
snippet "varc" "string|array fixedTrim" b
\$\{${1:variable[*]}%${2:stringToTrim}\}$0
endsnippet
snippet "unset " "delete array member[n]" b
unset ${1:array}${2:[}
endsnippet
snippet "xargs -I '{}'" "-n nrWords -d delim, pipe placeholder '{}'" b
xargs -I '{}' $0
endsnippet
snippet printf "print %s string %b binary" b
printf '%s ${2:text}\n' "\$${1:var}"
endsnippet
snippet join "-t delim -1 field_file1 -2 field_file2 file1 2" b
join -t'${1:delim}' ./${2:file1} ./${3:file2} -1 ${4:field of $3} ${5:field of $4} $0
endsnippet
snippet comm "-12 print only lines in file1&2 both 3"
comm ${1:--output-delimiter=} ./${2:file1} ./${3:file2}
endsnippet
snippet paste "-d delim -s file ,'-' for each column in outFile" b
paste -d'${1:,}' -s./${2:file} ${3:- - -}
endsnippet
snippet wc "-w wordCount -l lines -m chars -c bytes" b
wc -w $0
endsnippet
snippet getopts "parse args passed to script" b
__ScriptVersion=${1:0.0.1}
#=== FUNCTION ================================================================
# NAME: usage
# DESCRIPTION: Display usage information.
#===============================================================================
function usage ()
{
echo "Usage : $0 [options] [--]
Options:
-h|help Display this message
-v|version Display script version
-f|file pdf file"
} # ---------- end of function usage ----------
#-----------------------------------------------------------------------
# Handle command line arguments
#-----------------------------------------------------------------------
while getopts ":hvf:" opt
do
case $opt in
h|help ) usage; exit 0 ;;
v|version ) echo "$0 -- Version $__ScriptVersion"; exit 0 ;;
f|file ) echo "file passed to script is $OPTARG";;
* ) echo -e "\n Option does not exist : $OPTARG\n"
usage; exit 1 ;;
esac # --- end of case ---
done
shift $((OPTIND-1))
endsnippet
snippet pes "perl substitute" b
perl -pi -e 's/${1:old_string}/${2:new_string}/g'
endsnippet
snippet safe "set shell safe options"
set -euo pipefail # safe shell opts
endsnippet
# [ -a FILE ] # [ -b FILE ] # [ -c FILE ] # [ -d FILE ] # [ -e FILE ] # [ -f FILE ] # [ -g FILE ] # [ -h FILE ] # [ -k FILE ] # [ -p FILE ] # [ -r FILE ] # [ -s FILE ] # [ -t FD ] # [ -u FILE ] # [ -w FILE ] # [ -x FILE ] # [ -O FILE ] # [ -G FILE ] # [ -L FILE ] # [ -N FILE ] # [ -S FILE ] # [ -D DIR ]