plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.
pull/1904/head
John D Pell 2021-09-19 01:00:07 -07:00
parent 070c35ab0c
commit 68f0cd6ebf
1 changed files with 23 additions and 14 deletions

View File

@ -58,16 +58,23 @@ function dirs-help() {
# Add bookmarking functionality # Add bookmarking functionality
# Usage: # Usage:
if [ ! -f ~/.dirs ]; then # if doesn't exist, create it : "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-~/.local/state}/Bash_it/dirs}"
touch ~/.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 else
source ~/.dirs touch "$BASH_IT_DIRS_BKS"
fi fi
alias L='cat ~/.dirs' alias L='cat "$BASH_IT_DIRS_BKS"'
# Goes to destination dir, otherwise stay in the dir # Goes to destination dir, otherwise stay in the dir
G () { function G()
{
about 'goes to destination dir' about 'goes to destination dir'
param '1: directory' param '1: directory'
example '$ G ..' example '$ G ..'
@ -76,7 +83,8 @@ G () {
cd "${1:-${PWD}}" ; cd "${1:-${PWD}}" ;
} }
S () { function S ()
{
about 'save a bookmark' about 'save a bookmark'
param '1: bookmark name' param '1: bookmark name'
example '$ S mybkmrk' example '$ S mybkmrk'
@ -84,13 +92,14 @@ S () {
[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; } [[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }
sed "/$@/d" ~/.dirs > ~/.dirs1; sed "/$@/d" "$BASH_IT_DIRS_BKS" > ~/.dirs1;
\mv ~/.dirs1 ~/.dirs; \mv ~/.dirs1 "$BASH_IT_DIRS_BKS";
echo "$@"=\""${PWD}"\" >> ~/.dirs; echo "$@"=\""${PWD}"\" >> "$BASH_IT_DIRS_BKS";
source ~/.dirs ; source "$BASH_IT_DIRS_BKS" ;
} }
R () { function R()
{
about 'remove a bookmark' about 'remove a bookmark'
param '1: bookmark name' param '1: bookmark name'
example '$ R mybkmrk' example '$ R mybkmrk'
@ -98,10 +107,10 @@ R () {
[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; } [[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }
sed "/$@/d" ~/.dirs > ~/.dirs1; sed "/$@/d" "$BASH_IT_DIRS_BKS" > ~/.dirs1;
\mv ~/.dirs1 ~/.dirs; \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 # Set the Bash option so that no '$' is required when using the above facility
shopt -s cdable_vars shopt -s cdable_vars