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/2001/head
John D Pell 2021-12-31 00:11:23 -08:00
parent 2e51e92699
commit d8e7b173b5
1 changed files with 59 additions and 49 deletions

View File

@ -58,48 +58,58 @@ 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?}" ]]; 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 () {
function G() {
about 'goes to destination dir'
param '1: directory'
example '$ G ..'
group 'dirs'
cd "${1:-${PWD}}" ;
cd "${1:-${PWD}}"
}
S () {
function S() {
about 'save a bookmark'
param '1: bookmark name'
example '$ S mybkmrk'
group 'dirs'
[[ $# -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;
\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 () {
function R() {
about 'remove a bookmark'
param '1: bookmark name'
example '$ R mybkmrk'
group 'dirs'
[[ $# -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;
\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