Skip to content

Commit

Permalink
plugins/dirs: use XDG_STATE_HOME
Browse files Browse the repository at this point in the history
Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.
  • Loading branch information
gaelicWizard committed Aug 22, 2021
1 parent a2c7493 commit f552a14
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions plugins/available/dirs.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@ function dirs-help() {
# Add bookmarking functionality
# Usage:

if [ ! -f ~/.dirs ]; then # if doesn't exist, create it
touch ~/.dirs
: ${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-~/.local/state}/Bash_it/dirs}
if [[ -f "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-~/.local/state}/Bash_it/dirs}" ]]
then
source "$BASH_IT_DIRS_BKS"
elif [[ -f ~/.dirs ]]
then
mv -vn ~/.dirs "$BASH_IT_DIRS_BKS"
source "$BASH_IT_DIRS_BKS"
else
source ~/.dirs
touch "$BASH_IT_DIRS_BKS"
fi

alias L='cat ~/.dirs'
alias L='cat "$BASH_IT_DIRS_BKS"'

# Goes to destination dir, otherwise stay in the dir
G () {
Expand All @@ -84,10 +90,10 @@ S () {

[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }

sed "/$@/d" ~/.dirs > ~/.dirs1;
\mv ~/.dirs1 ~/.dirs;
echo "$@"=\"`pwd`\" >> ~/.dirs;
source ~/.dirs ;
sed "/$@/d" "$BASH_IT_DIRS_BKS" > ~/.dirs1;
\mv ~/.dirs1 "$BASH_IT_DIRS_BKS";
echo "$@"=\"`pwd`\" >> "$BASH_IT_DIRS_BKS";
source "$BASH_IT_DIRS_BKS" ;
}

R () {
Expand All @@ -98,10 +104,10 @@ R () {

[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }

sed "/$@/d" ~/.dirs > ~/.dirs1;
\mv ~/.dirs1 ~/.dirs;
sed "/$@/d" "$BASH_IT_DIRS_BKS" > ~/.dirs1;
\mv ~/.dirs1 "$BASH_IT_DIRS_BKS";
}

alias U='source ~/.dirs' # Update bookmark stack
alias U='source "$BASH_IT_DIRS_BKS"' # Update bookmark stack
# Set the Bash option so that no '$' is required when using the above facility
shopt -s cdable_vars

0 comments on commit f552a14

Please sign in to comment.