aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/keep.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-09-30 12:07:27 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-09-30 12:07:27 +1300
commitd585e3fedcf4416d8b098ffa68c616964467a3a1 (patch)
treedecf83bb8f5769daeaf34ec5a500192ccf0bc563 /bash/bashrc.d/keep.bash
parent1dba8f76082cfaf7365ad5e561311f492624bac4 (diff)
downloaddotfiles-d585e3fedcf4416d8b098ffa68c616964467a3a1.tar.gz
dotfiles-d585e3fedcf4416d8b098ffa68c616964467a3a1.zip
Stop `keep` writing empty files for undef vars
Diffstat (limited to 'bash/bashrc.d/keep.bash')
-rw-r--r--bash/bashrc.d/keep.bash25
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