diff --git a/.vim/templates/sh b/.vim/templates/sh index 0bb8ae1..861e200 100644 --- a/.vim/templates/sh +++ b/.vim/templates/sh @@ -16,11 +16,44 @@ set -o nounset # Treat unset variables as an error -# Check for empty argument +# set variables +declare -r TRUE=0 +declare -r FALSE=1 + +################################################################## +# Purpose: Check for empty argument +# Arguments: at least one +# Return: Either error message or exit with an error code 1 +################################################################## if [ -z "${1:-}" ]; then - arg="undefined" + arg="undefined" + echo "Required Argument Missing" + #exit 1 else - arg=$1 + arg=$1 fi -. +################################################################## +# Purpose: Send output to screen and specified file +# Requires: define to `logfile` variable to send out put to logfile +# Usage: logecho "Log Message" +################################################################## +logfile= +logecho() { + echo "${1}" + if [[ ! -z "${logfile}" ]]; then + echo "${1}" >> "${logfile}" + fi +} + +################################################################## +# Purpose: Return true if script is executed by the root user +# Arguments: none +# Return: True or False +# Usage: is_root && echo "root" || echo "not root" +################################################################## +function is_root() +{ + [ $(id -u) -eq 0 ] && return $TRUE || return $FALSE +} + diff --git a/.vimrc b/.vimrc index 44fe43f..cecb4db 100644 --- a/.vimrc +++ b/.vimrc @@ -244,11 +244,11 @@ nnoremap ,begend :-1read $HOME/.vim/templates/begendjA " ==> Templates: shell scripts (.sh) autocmd BufNewFile *.sh so $HOME/.vim/templates/sh -autocmd BufNewFile *.sh %s/FILE:.*/\='FILE: '.expand('%')/e +autocmd BufNewFile *.sh %s/FILE:.*/\='FILE: '.expand('%:t')/e autocmd BufNewFile *.sh exe "g/AUTHOR:.*/s//AUTHOR: C Hawley" -autocmd BufNewFile *.sh exe "g/CREATED:.*/s//CREATED: " .strftime("%c") +autocmd BufNewFile *.sh exe "g/CREATED:.*/s//CREATED: " .strftime("%Y-%m-%d") autocmd BufWritePre,filewritepre *.sh execute "normal ma" -autocmd BufWritePre,filewritepre *.sh exe "g/REVISION:.*/s//REVISION: " .strftime("%c") +autocmd BufWritePre,filewritepre *.sh exe "g/REVISION:.*/s//REVISION: " .strftime("%Y-%m-%d") autocmd bufWritePost,filewritepost *.sh execute "normal `a" " ---------------------------------------------------------------------------------------------------------------------