Added snippets for Emacs
This commit is contained in:
44
emacs/.emacs.d/snippets/sh-mode/args
Normal file
44
emacs/.emacs.d/snippets/sh-mode/args
Normal file
@@ -0,0 +1,44 @@
|
||||
#key: args
|
||||
# --
|
||||
|
||||
read_user_input() {
|
||||
local opts=
|
||||
opts=$(getopt \
|
||||
-o hr:nv \
|
||||
--long help \
|
||||
--long version: \
|
||||
--long dry-run \
|
||||
--long verbose \
|
||||
-n 'parse-options' \
|
||||
-- "$@")
|
||||
if [ $? != 0 ] ; then
|
||||
echo "Failed parsing options." >&2
|
||||
exit 1
|
||||
fi
|
||||
eval set -- "$opts"
|
||||
|
||||
while true; do
|
||||
case "\$1" in
|
||||
-h | --help)
|
||||
print_help;
|
||||
exit 0
|
||||
break;;
|
||||
-r | --version)
|
||||
export version=\$2
|
||||
shift 2;;
|
||||
-n | --dry-run)
|
||||
export dry_run=1
|
||||
shift;;
|
||||
-v | --verbose)
|
||||
export verbose=1
|
||||
shift;;
|
||||
-- )
|
||||
shift;
|
||||
break ;;
|
||||
* )
|
||||
break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
export rest_of_args=$*
|
||||
}
|
||||
3
emacs/.emacs.d/snippets/sh-mode/aw
Normal file
3
emacs/.emacs.d/snippets/sh-mode/aw
Normal file
@@ -0,0 +1,3 @@
|
||||
#name: aw
|
||||
# --
|
||||
awk '{print \$${1:1}\}'$0
|
||||
18
emacs/.emacs.d/snippets/sh-mode/cmd
Normal file
18
emacs/.emacs.d/snippets/sh-mode/cmd
Normal file
@@ -0,0 +1,18 @@
|
||||
#name : cmd
|
||||
# --
|
||||
#! /usr/bin/env bash
|
||||
|
||||
## author: torstein, torstein@skybert.net
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
main() {
|
||||
:
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
|
||||
|
||||
5
emacs/.emacs.d/snippets/sh-mode/cwd
Normal file
5
emacs/.emacs.d/snippets/sh-mode/cwd
Normal file
@@ -0,0 +1,5 @@
|
||||
#name: cwd
|
||||
# --
|
||||
local _cwd=
|
||||
_cwd="$(cd "\$(dirname "\${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
|
||||
$0
|
||||
5
emacs/.emacs.d/snippets/sh-mode/eof
Normal file
5
emacs/.emacs.d/snippets/sh-mode/eof
Normal file
@@ -0,0 +1,5 @@
|
||||
#name : eof
|
||||
# --
|
||||
cat <<EOF
|
||||
$0
|
||||
EOF
|
||||
5
emacs/.emacs.d/snippets/sh-mode/fn
Normal file
5
emacs/.emacs.d/snippets/sh-mode/fn
Normal file
@@ -0,0 +1,5 @@
|
||||
#name : fn
|
||||
# --
|
||||
${1:read_user_input}() {
|
||||
$0
|
||||
}
|
||||
7
emacs/.emacs.d/snippets/sh-mode/fnae
Normal file
7
emacs/.emacs.d/snippets/sh-mode/fnae
Normal file
@@ -0,0 +1,7 @@
|
||||
assertEquals() {
|
||||
test "\$1" = "\$2" || {
|
||||
printf "Failed: Expected: [%s] Actual: [%s]\\n" "\${1}" "\${2}"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
$0
|
||||
6
emacs/.emacs.d/snippets/sh-mode/fo
Normal file
6
emacs/.emacs.d/snippets/sh-mode/fo
Normal file
@@ -0,0 +1,6 @@
|
||||
#name : fo
|
||||
# --
|
||||
for ${1:el} in \$\{${2:list}\}; do
|
||||
echo "\${$1}"
|
||||
$0
|
||||
done
|
||||
19
emacs/.emacs.d/snippets/sh-mode/help
Normal file
19
emacs/.emacs.d/snippets/sh-mode/help
Normal file
@@ -0,0 +1,19 @@
|
||||
#name : help
|
||||
# --
|
||||
_show_help() {
|
||||
cat <<EOF
|
||||
NAME
|
||||
$(basename "\$0")
|
||||
|
||||
SYNOPSIS
|
||||
$(basename "\$0")
|
||||
|
||||
OPTIONS
|
||||
--help Don't panic
|
||||
|
||||
AUTHORS
|
||||
skybert wrote the initial version.
|
||||
|
||||
$0
|
||||
EOF
|
||||
}
|
||||
5
emacs/.emacs.d/snippets/sh-mode/if
Normal file
5
emacs/.emacs.d/snippets/sh-mode/if
Normal file
@@ -0,0 +1,5 @@
|
||||
#name : if
|
||||
# --
|
||||
if [ ${1} ]; then
|
||||
$0
|
||||
fi
|
||||
5
emacs/.emacs.d/snippets/sh-mode/iif
Normal file
5
emacs/.emacs.d/snippets/sh-mode/iif
Normal file
@@ -0,0 +1,5 @@
|
||||
#name : iif
|
||||
# --
|
||||
if [[ ${1} ]]; then
|
||||
$0
|
||||
fi
|
||||
7
emacs/.emacs.d/snippets/sh-mode/main
Normal file
7
emacs/.emacs.d/snippets/sh-mode/main
Normal file
@@ -0,0 +1,7 @@
|
||||
#name : main
|
||||
# --
|
||||
main() {
|
||||
$0
|
||||
}
|
||||
|
||||
main "$@"
|
||||
3
emacs/.emacs.d/snippets/sh-mode/pr
Normal file
3
emacs/.emacs.d/snippets/sh-mode/pr
Normal file
@@ -0,0 +1,3 @@
|
||||
#name : pr
|
||||
# --
|
||||
printf "%s\\\n" "\${$0}"
|
||||
27
emacs/.emacs.d/snippets/sh-mode/shunit
Normal file
27
emacs/.emacs.d/snippets/sh-mode/shunit
Normal file
@@ -0,0 +1,27 @@
|
||||
#name : shunit
|
||||
# --
|
||||
#! /usr/bin/env bash
|
||||
|
||||
# by torstein@skybert.net
|
||||
|
||||
cwd="\$(cd "$(dirname "\${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
|
||||
|
||||
## @override shunit2
|
||||
setUp() {
|
||||
source "\${cwd}/../lib/$(basename "\$0" -test.sh)-lib.sh"
|
||||
}
|
||||
|
||||
## @override shunit2
|
||||
tearDown() {
|
||||
:
|
||||
}
|
||||
|
||||
main() {
|
||||
test -d "\${cwd}"/shunit2 || {
|
||||
git -C "\${cwd}" clone --quiet --depth 1 https://github.com/kward/shunit2.git
|
||||
}
|
||||
|
||||
source "\${cwd}"/shunit2/shunit2
|
||||
}
|
||||
|
||||
main "\$@"
|
||||
21
emacs/.emacs.d/snippets/sh-mode/test
Normal file
21
emacs/.emacs.d/snippets/sh-mode/test
Normal file
@@ -0,0 +1,21 @@
|
||||
#name : test
|
||||
# --
|
||||
#! /usr/bin/env bash
|
||||
|
||||
## author: torstein, torstein@skybert.net
|
||||
|
||||
## @override shunit2
|
||||
setUp() {
|
||||
source "$(dirname "\$0")/../lib/$(basename "\$0" -test.sh).sh"
|
||||
}
|
||||
|
||||
## @override shunit2
|
||||
tearDown() {
|
||||
:
|
||||
}
|
||||
|
||||
main() {
|
||||
. "$(dirname "\$0")"/shunit2/shunit2
|
||||
}
|
||||
|
||||
main "$@"
|
||||
8
emacs/.emacs.d/snippets/sh-mode/tmpdir
Normal file
8
emacs/.emacs.d/snippets/sh-mode/tmpdir
Normal file
@@ -0,0 +1,8 @@
|
||||
#name : tmpdir
|
||||
# --
|
||||
local ${1:tmp_dir}=
|
||||
$1=\$(mktemp -d)
|
||||
|
||||
$0
|
||||
|
||||
rm -rf "\${$1\}"
|
||||
3
emacs/.emacs.d/snippets/sh-mode/v
Normal file
3
emacs/.emacs.d/snippets/sh-mode/v
Normal file
@@ -0,0 +1,3 @@
|
||||
#name : v
|
||||
# --
|
||||
"\${$1}"$0
|
||||
4
emacs/.emacs.d/snippets/sh-mode/va
Normal file
4
emacs/.emacs.d/snippets/sh-mode/va
Normal file
@@ -0,0 +1,4 @@
|
||||
#name : va
|
||||
# --
|
||||
local ${1:dir}=
|
||||
$1=$($0)
|
||||
3
emacs/.emacs.d/snippets/sh-mode/vd
Normal file
3
emacs/.emacs.d/snippets/sh-mode/vd
Normal file
@@ -0,0 +1,3 @@
|
||||
#name : vad
|
||||
# --
|
||||
local ${1:dir}=$0
|
||||
6
emacs/.emacs.d/snippets/sh-mode/wh
Normal file
6
emacs/.emacs.d/snippets/sh-mode/wh
Normal file
@@ -0,0 +1,6 @@
|
||||
#name : wh
|
||||
# --
|
||||
while read -r ${1:f}; do
|
||||
echo "\${$1}"
|
||||
$0
|
||||
done
|
||||
Reference in New Issue
Block a user