bin/sym.completion in sym-2.7.0 vs bin/sym.completion in sym-2.8.0

- old
+ new

@@ -1,13 +1,28 @@ #!/usr/bin/env bash # -# Sym command line completion +# Sym Command Line completion and other utilities +# +# © 2015-2018, Konstantin Gredeskoul, https://github.com/kigster/sym # -# © 2015-2016, Konstantin Gredeskoul, https://github.com/kigster/sym # MIT LICENSE # +########################################################################### +( [[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] || \ + [[ -n $BASH_VERSION && $0 != "$BASH_SOURCE" ]]) && _s_=1 || _s_=0 + +bash_version=$(/usr/bin/env bash --version | awk '{FS="version"}{print $4}') +bash_version=${bash_version:0:1} + +if [[ "${bash_version}" -lt 4 ]]; then + echo "Sym BASH helpers are incompatible with BASH version 3 or older." + echo "Please upgrade your BASH to version 4+ released in 2009. Srsly." + (( $_s_ )) && return 1 + (( $_s_ )) || exit 1 +fi + declare -a bash_completion_locations=(/usr/local/etc/bash_completion /usr/etc/bash_completion /etc/bash_completion) loaded=false for file in ${bash_completion_locations[@]}; do [[ -s $file ]] && { source $file @@ -61,9 +76,56 @@ ;; esac return 0 } && complete -F _sym $nospace $filenames sym + +sym-encrypt() { + local key=$1 + local from=$2 + local to=$3 + local args= + + [[ -n $key ]] && args="${args} -ck ${key}" + + if [[ -n $to ]]; then + args="${args} -o ${to}" + [[ -n $from ]] && args="${args} -f ${from}" + else + [[ -n $from ]] && args="${args} -n ${from}" + fi + + if [[ -z $args ]]; then + echo "usage: sym-encrypt key file [ outfile ]" + else + sym -e ${args} + fi +} + +sym-decrypt() { + local key=$1 + local from=$2 + local to=$3 + local args= + + [[ -n $key ]] && args="${args} -ck ${key}" + + if [[ -n $to ]]; then + args="${args} -o ${to}" + [[ -n $from ]] && args="${args} -f ${from}" + else + [[ -n $from ]] && args="${args} -n ${from}" + fi + + if [[ -z $args ]]; then + echo "usage: sym-decrypt key file [ outfile ]" + else + sym -d ${args} + fi +} + +alias syme="sym-encrypt" +alias symd="sym-decrypt" # Local variables: # mode: shell-script # sh-basic-offset: 4 # sh-indent-comment: t