From d585e3fedcf4416d8b098ffa68c616964467a3a1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 30 Sep 2016 12:07:27 +1300 Subject: Stop `keep` writing empty files for undef vars --- bash/bashrc.d/keep.bash | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/bash/bashrc.d/keep.bash b/bash/bashrc.d/keep.bash index 8f6a6fdb..a8c3456a 100644 --- a/bash/bashrc.d/keep.bash +++ b/bash/bashrc.d/keep.bash @@ -101,19 +101,18 @@ EOF # If -d was given, delete the keep files for the NAME if ((delete)) ; then - rm -- "$bashkeep"/"$name".bash || ((errors++)) - - # Otherwise, attempt to create the keep file, using an - # appropriate call to the declare builtin - else - { case $(type -t "$name") in - 'function') - declare -f -- "$name" - ;; - *) - declare -p -- "$name" - ;; - esac ; } > "$bashkeep"/"$name".bash || ((errors++)) + rm -- "$bashkeep"/"$name".bash || + ((errors++)) + + # Save a function + elif [[ $(type -t "$name") = 'function' ]] ; then + declare -f -- "$name" >"$bashkeep"/"$name".bash || + ((errors++)) + + # Save a variable + elif declare -p -- "$name" >/dev/null ; then + declare -p -- "$name" >"$bashkeep"/"$name".bash || + ((errors++)) fi ;; esac -- cgit v1.2.3