mirror of
https://github.com/Mayccoll/Gogh.git
synced 2023-08-10 21:12:46 +03:00
Make sure exported variables get unset to avoid global variable pollution
This commit is contained in:
parent
5bdddddd62
commit
01f998e9ee
@ -10,6 +10,35 @@ GS="${GS:-$(command -v gsettings | xargs echo)}"
|
|||||||
# Note: xargs echo is to make the command sucessful even if it was not
|
# Note: xargs echo is to make the command sucessful even if it was not
|
||||||
# otherwise the script will exit if the command does not exist (elementary os)
|
# otherwise the script will exit if the command does not exist (elementary os)
|
||||||
|
|
||||||
|
# |
|
||||||
|
# | Make sure all exported variables get unset no matter what
|
||||||
|
# | Defining this in this script because it gets called even if
|
||||||
|
# | gogh.sh was not called. Exported variables in gogh.sh gets
|
||||||
|
# | handled there in case there was en error before this script was called
|
||||||
|
# | ============================================
|
||||||
|
GLOBAL_VAR_CLEANUP() {
|
||||||
|
unset PROFILE_NAME
|
||||||
|
unset PROFILE_SLUG
|
||||||
|
unset scratchdir
|
||||||
|
unset TILIX_RES
|
||||||
|
unset TERMINAL
|
||||||
|
unset LOOP
|
||||||
|
unset OPTLENGTH
|
||||||
|
|
||||||
|
for c in $(seq -s " " -w 16); do
|
||||||
|
unset DEMO_COLOR_${c}
|
||||||
|
unset COLOR_${c}
|
||||||
|
done
|
||||||
|
|
||||||
|
unset BACKGROUND_COLOR
|
||||||
|
unset FOREGROUND_COLOR
|
||||||
|
unset CURSOR_COLOR
|
||||||
|
unset PROFILE_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
# Note: Since all scripts gets invoked in a subshell the traps from the parent shell
|
||||||
|
# will not get inherited. Hence traps defined in gogh.sh and print-themes.sh will still trigger
|
||||||
|
trap 'GLOBAL_VAR_CLEANUP; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
|
||||||
|
|
||||||
# |
|
# |
|
||||||
# | Second test for TERMINAL in case user ran
|
# | Second test for TERMINAL in case user ran
|
||||||
@ -252,6 +281,7 @@ if [[ "${COLORTERM:-}" == "truecolor" ]] || [[ "${COLORTERM:-}" == "24bit" ]]; t
|
|||||||
[[ "$c" == "08" ]] && color_str+="\n" # new line
|
[[ "$c" == "08" ]] && color_str+="\n" # new line
|
||||||
done
|
done
|
||||||
printf '\n%b\n\n\n' "${color_str}"
|
printf '\n%b\n\n\n' "${color_str}"
|
||||||
|
unset color_str
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
function gogh_colors () {
|
function gogh_colors () {
|
||||||
@ -262,6 +292,7 @@ else
|
|||||||
[[ $c == 7 ]] && color_str+="\n" # new line
|
[[ $c == 7 ]] && color_str+="\n" # new line
|
||||||
done
|
done
|
||||||
printf '\n%b\n\n' "${color_str}"
|
printf '\n%b\n\n' "${color_str}"
|
||||||
|
unset color_str
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -594,4 +625,4 @@ esac
|
|||||||
|
|
||||||
unset PROFILE_NAME
|
unset PROFILE_NAME
|
||||||
unset PROFILE_SLUG
|
unset PROFILE_SLUG
|
||||||
unset DEFAULT_SLUG
|
unset DEFAULT_SLUG
|
||||||
|
18
gogh.sh
18
gogh.sh
@ -1,5 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Define traps and trapfunctions early in case any errors before script exits
|
||||||
|
GLOBAL_VAR_CLEANUP(){
|
||||||
|
[[ -n "$(command -v TILIX_TMP_CLEANUP)" ]] && TILIX_TMP_CLEANUP
|
||||||
|
unset PROFILE_NAME
|
||||||
|
unset PROFILE_SLUG
|
||||||
|
unset TILIX_RES
|
||||||
|
unset TERMINAL
|
||||||
|
}
|
||||||
|
|
||||||
|
trap 'GLOBAL_VAR_CLEANUP; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
|
||||||
|
|
||||||
declare -a THEMES=(
|
declare -a THEMES=(
|
||||||
'3024-day.sh'
|
'3024-day.sh'
|
||||||
'3024-night.sh'
|
'3024-night.sh'
|
||||||
@ -341,18 +352,17 @@ if [[ "$TERMINAL" = "tilix" ]] && [[ ${#OPTION[@]} -gt 0 ]]; then
|
|||||||
# | desides to abort before all themes has been processed this section will cleanup the tmpdir
|
# | desides to abort before all themes has been processed this section will cleanup the tmpdir
|
||||||
# | =======================================
|
# | =======================================
|
||||||
if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then
|
if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then
|
||||||
cleanup() {
|
TILIX_TMP_CLEANUP() {
|
||||||
echo
|
echo
|
||||||
echo "Cleaning up"
|
echo "Cleaning up"
|
||||||
rm -rf "$scratchdir"
|
rm -rf "$scratchdir"
|
||||||
unset LOOP OPTLENGTH
|
unset LOOP OPTLENGTH scratchdir
|
||||||
echo "Done..."
|
echo "Done..."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
scratchdir=$(mktemp -d -t tmp.XXXXXXXX)
|
scratchdir=$(mktemp -d -t tmp.XXXXXXXX)
|
||||||
export scratchdir
|
export scratchdir
|
||||||
trap 'cleanup; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -400,4 +410,4 @@ for OP in "${OPTION[@]#0}"; do
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
command -v bar::stop > /dev/null && bar::stop || :
|
command -v bar::stop > /dev/null && bar::stop || :
|
||||||
|
Loading…
x
Reference in New Issue
Block a user