Skip to content

Commit

Permalink
refactor(scratch file): don't use a variable for the path
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Feb 28, 2020
1 parent 80e1ae9 commit 3910d2a
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ _zsh_abbr() {
return
fi
else
source "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"
source "${TMPDIR:-/tmp}/zsh-user-abbreviations"

if (( ${+ZSH_USER_ABBREVIATIONS[$1]} )); then
unset "ZSH_USER_ABBREVIATIONS[${(b)1}]"
Expand Down Expand Up @@ -283,7 +283,7 @@ _zsh_abbr() {
return
fi

source "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"
source "${TMPDIR:-/tmp}/zsh-user-abbreviations"

print -l ${(k)ZSH_USER_ABBREVIATIONS}
print -l ${(k)ZSH_SESSION_ABBREVIATIONS}
Expand Down Expand Up @@ -408,7 +408,7 @@ _zsh_abbr() {
if $opt_session; then
ZSH_SESSION_ABBREVIATIONS[$abbreviation]="$expansion"
else
source "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"
source "${TMPDIR:-/tmp}/zsh-user-abbreviations"
ZSH_USER_ABBREVIATIONS[$abbreviation]="$expansion"
util_sync_user
fi
Expand Down Expand Up @@ -477,9 +477,9 @@ _zsh_abbr() {
return
fi

user_updated="$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"_updated
user_updated="${TMPDIR:-/tmp}/zsh-user-abbreviations"_updated

typeset -p ZSH_USER_ABBREVIATIONS > "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"
typeset -p ZSH_USER_ABBREVIATIONS > "${TMPDIR:-/tmp}/zsh-user-abbreviations"

rm "$user_updated" 2> /dev/null
touch "$user_updated"
Expand Down Expand Up @@ -629,8 +629,6 @@ _zsh_abbr() {

if $opt_add; then
add "$@"
elif $opt_output_aliases; then
output_aliases "$@"
elif $opt_clear_session; then
clear_session "$@"
elif $opt_erase; then
Expand All @@ -641,6 +639,8 @@ _zsh_abbr() {
git_populate "$@"
elif $opt_list; then
list "$@"
elif $opt_output_aliases; then
output_aliases "$@"
elif $opt_populate; then
populate "$@"
elif $opt_print_version; then
Expand Down Expand Up @@ -717,7 +717,7 @@ _zsh_abbr_expansion() {
expansion="${ZSH_SESSION_ABBREVIATIONS[$1]}"

if [[ ! -n $expansion ]]; then
source "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"
source "${TMPDIR:-/tmp}/zsh-user-abbreviations"
expansion="${ZSH_USER_ABBREVIATIONS[$1]}"
fi

Expand All @@ -739,11 +739,9 @@ _zsh_abbr_init() {
fi

# Scratch file
ZSH_USER_ABBREVIATIONS_SCRATCH_FILE="${TMPDIR:-/tmp}/zsh-user-abbreviations"

rm "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE" 2> /dev/null
touch "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE" 1> /dev/null
chmod 600 "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"
rm "${TMPDIR:-/tmp}/zsh-user-abbreviations" 2> /dev/null
touch "${TMPDIR:-/tmp}/zsh-user-abbreviations"
chmod 600 "${TMPDIR:-/tmp}/zsh-user-abbreviations"

# Load saved user abbreviations
if [ -f "$ZSH_USER_ABBREVIATIONS_PATH" ]; then
Expand All @@ -761,7 +759,7 @@ _zsh_abbr_init() {
touch "$ZSH_USER_ABBREVIATIONS_PATH"
fi

typeset -p ZSH_USER_ABBREVIATIONS > "$ZSH_USER_ABBREVIATIONS_SCRATCH_FILE"
typeset -p ZSH_USER_ABBREVIATIONS > "${TMPDIR:-/tmp}/zsh-user-abbreviations"
}


Expand Down

0 comments on commit 3910d2a

Please sign in to comment.