diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-30 12:07:27 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-30 12:07:27 +1300 |
commit | d585e3fedcf4416d8b098ffa68c616964467a3a1 (patch) | |
tree | decf83bb8f5769daeaf34ec5a500192ccf0bc563 /bash/bashrc.d | |
parent | Update submodules (diff) | |
download | dotfiles-d585e3fedcf4416d8b098ffa68c616964467a3a1.tar.gz dotfiles-d585e3fedcf4416d8b098ffa68c616964467a3a1.zip |
Stop `keep` writing empty files for undef vars
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/keep.bash | 25 |
1 files 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 |