From: Antonio Ospite Date: Tue, 22 Jan 2019 22:16:17 +0000 (+0100) Subject: Make more function variables local to avoid polluting the environment X-Git-Url: https://git.ao2.it/config/bash.git/commitdiff_plain/ef18a3253cea6e279b2a5de23e9a1edef3bfa941?ds=inline;hp=b8788419dde6ed6e9c2bb430957f87ea1677467c Make more function variables local to avoid polluting the environment --- diff --git a/.bash/aliases.d/archives b/.bash/aliases.d/archives index b708078..bd2a435 100644 --- a/.bash/aliases.d/archives +++ b/.bash/aliases.d/archives @@ -7,7 +7,7 @@ then function gztar() { [ -d "$1" ] || { echo "usage: gztar [tar options]" 1>&2; exit 1; } - DIR="$1" + local DIR="$1" shift tar "$@" -czvf "$(basename "$DIR").tar.gz" "$DIR" } @@ -15,7 +15,7 @@ then function bztar() { [ -d "$1" ] || { echo "usage: bztar [tar options]" 1>&2; exit 1; } - DIR="$1" + local DIR="$1" shift tar "$@" -cjvf "$(basename "$DIR").tar.bz2" "$DIR" } @@ -23,7 +23,7 @@ then function xztar() { [ -d "$1" ] || { echo "usage: xztar [tar options]" 1>&2; exit 1; } - DIR="$1" + local DIR="$1" shift tar "$@" -cJvf "$(basename "$DIR").tar.xz" "$DIR" } diff --git a/.bash/aliases.d/debian b/.bash/aliases.d/debian index 7efbc63..b65caa1 100644 --- a/.bash/aliases.d/debian +++ b/.bash/aliases.d/debian @@ -10,6 +10,7 @@ if command -v aptitude &> /dev/null; then function aptitude-remove-dep() { + local PACKAGES PACKAGES=$(apt-cache showsrc "$1" | grep Build-Depends | perl -p -e 's/(?:[\[(].+?[\])]|Build-Depends:|,|\|)//g') sudo aptitude markauto "$PACKAGES" } diff --git a/.bash/aliases.d/record b/.bash/aliases.d/record index 00372b3..fb90aa7 100644 --- a/.bash/aliases.d/record +++ b/.bash/aliases.d/record @@ -4,16 +4,19 @@ if command -v script &> /dev/null; then function record() { + local TIMESTAMP TIMESTAMP="$(date '+%Y-%m-%d-%H:%M:%S')" # The trick here is to use 'type' to eat any leading environment variables # and get to the command name. + local COMMAND_NAME COMMAND_NAME="$(type -P "$@" 2>/dev/null | cut -d ' ' -f 1)" [ "x$COMMAND_NAME" = "x" ] && return 1 # Escape the argument so that it can be reused as shell input # NOTE: this is Bash specific. + local COMMAND_ESCAPED COMMAND_ESCAPED=$(printf "%q " "$@") script -q -e -c "$COMMAND_ESCAPED" "${TIMESTAMP}_$(basename "$COMMAND_NAME").log"