diff --git a/snippets/sh-mode/add-section b/snippets/sh-mode/add-section new file mode 100644 index 0000000..a38c8de --- /dev/null +++ b/snippets/sh-mode/add-section @@ -0,0 +1,16 @@ +# -*- mode: Shell-script -*- +# name:add-section +# key:adds +# -- +############################################################# +# 1 - STEP NAME +############################################################# +${3:my_func}() { + local step_name='STEP ${1:1} ${2:STEP NAME}' + warn "Press enter to proceed with $step_name"; read + info "$step_name" + + $0 + + info "done" +} \ No newline at end of file diff --git a/snippets/sh-mode/cat-heredoc b/snippets/sh-mode/cat-heredoc new file mode 100644 index 0000000..728fc04 --- /dev/null +++ b/snippets/sh-mode/cat-heredoc @@ -0,0 +1,7 @@ +# -*- mode: Shell-script -*- +# name:cat-heredoc +# key:cat +# -- +cat < +############################################################# + +doc=$(cat <<'EOF' +NOTES: + +EOF +) + +############################################################# +# SETUP SECTION +############################################################# +set -e +set -o pipefail + +############################################################# +# HELPER FUNCTIONS +############################################################# +info() { + GREEN='\033[1;32m' + NC='\033[0m' + echo -e "\${GREEN}\${1}\${NC}" +} + +trace() { + YELLOW='\033[1;33m' + NC='\033[0m' + echo -e "\${YELLOW}\${1}\${NC}" +} + +warn() { + PURPLE='\033[1;35m' + NC='\033[0m' + echo -e "\${PURPLE}\${1}\${NC}" +} + +error() { + RED='\033[1;31m' + NC='\033[0m' + echo -e "\${RED}\${1}\${NC}" +} + +$0 + +############################################################# +# RUN SECTION +############################################################# +echo $(date +'%Y-%m-%d %H:%M') +info "$doc" + +info "Bye!" + +exit 0 diff --git a/snippets/sh-mode/sourced-check b/snippets/sh-mode/sourced-check new file mode 100644 index 0000000..b4ff95e --- /dev/null +++ b/snippets/sh-mode/sourced-check @@ -0,0 +1,8 @@ +# -*- mode: Shell-script -*- +# name:sourced-check +# key:sourced +# -- +if [ \$0 == $BASH_SOURCE ]; then + error "Do not run the script in a subshell via ./ Instead you should 'source' it!" + exit 1 +fi diff --git a/snippets/sh-mode/systemd b/snippets/sh-mode/systemd new file mode 100644 index 0000000..b494f23 --- /dev/null +++ b/snippets/sh-mode/systemd @@ -0,0 +1,23 @@ +# -*- mode: Shell-script -*- +# name:systemd +# key:systemd +# -- +[Unit] +Description=Description goes here +Wants=network.target + +[Service] +Environment="VAR_NAME=value" +EnvironmentFile=-/etc/environment +ExecStart=/usr/bin/bash /home/myuser/myscript.sh${1} +SyslogIdentifier=my.service +Restart=on-failure +RestartSec=5 +# Should exist! +WorkingDirectory=/var/my.service${2} +TimeoutStopSec=30 +Type=simple +User=root + +[Install] +WantedBy=multi-user.target diff --git a/snippets/sh-mode/wget b/snippets/sh-mode/wget new file mode 100644 index 0000000..79ebd16 --- /dev/null +++ b/snippets/sh-mode/wget @@ -0,0 +1,5 @@ +# -*- mode: Shell-script -*- +# name:wget +# key:wget +# -- +wget --continue ${1:link} --output-document ${2:file} \ No newline at end of file