Merge pull request #2001 from gaelicWizard/plugin-dirs
Plugin/dirs: use `$XDG_STATE_HOME`pull/2007/head
commit
c060eb46ea
|
|
@ -88,6 +88,7 @@ plugins/available/basher.plugin.bash
|
||||||
plugins/available/blesh.plugin.bash
|
plugins/available/blesh.plugin.bash
|
||||||
plugins/available/cmd-returned-notify.plugin.bash
|
plugins/available/cmd-returned-notify.plugin.bash
|
||||||
plugins/available/direnv.plugin.bash
|
plugins/available/direnv.plugin.bash
|
||||||
|
plugins/available/dirs.plugin.bash
|
||||||
plugins/available/docker-machine.plugin.bash
|
plugins/available/docker-machine.plugin.bash
|
||||||
plugins/available/git-subrepo.plugin.bash
|
plugins/available/git-subrepo.plugin.bash
|
||||||
plugins/available/git.plugin.bash
|
plugins/available/git.plugin.bash
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
# Directory stack navigation:
|
# Directory stack navigation:
|
||||||
#
|
#
|
||||||
# Add to stack with: pu /path/to/directory
|
# Add to stack with: pu /path/to/directory
|
||||||
|
|
@ -58,48 +59,61 @@ 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?}" ]]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "${BASH_IT_DIRS_BKS?}"
|
||||||
|
elif [[ -f ~/.dirs ]]; then
|
||||||
|
mv -vn ~/.dirs "${BASH_IT_DIRS_BKS?}"
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
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 ..'
|
||||||
group 'dirs'
|
group 'dirs'
|
||||||
|
|
||||||
cd "${1:-${PWD}}" ;
|
cd "${1:-${PWD}}" || return
|
||||||
}
|
}
|
||||||
|
|
||||||
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'
|
||||||
group 'dirs'
|
group 'dirs'
|
||||||
|
|
||||||
[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }
|
[[ $# -eq 1 ]] || {
|
||||||
|
echo "${FUNCNAME[0]} function requires 1 argument"
|
||||||
sed "/$@/d" ~/.dirs > ~/.dirs1;
|
return 1
|
||||||
\mv ~/.dirs1 ~/.dirs;
|
|
||||||
echo "$@"=\""${PWD}"\" >> ~/.dirs;
|
|
||||||
source ~/.dirs ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
R () {
|
sed "/$1/d" "${BASH_IT_DIRS_BKS?}" > "${BASH_IT_DIRS_BKS?}.new"
|
||||||
|
command mv "${BASH_IT_DIRS_BKS?}.new" "${BASH_IT_DIRS_BKS?}"
|
||||||
|
echo "$1"=\""${PWD}"\" >> "${BASH_IT_DIRS_BKS?}"
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "${BASH_IT_DIRS_BKS?}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function R() {
|
||||||
about 'remove a bookmark'
|
about 'remove a bookmark'
|
||||||
param '1: bookmark name'
|
param '1: bookmark name'
|
||||||
example '$ R mybkmrk'
|
example '$ R mybkmrk'
|
||||||
group 'dirs'
|
group 'dirs'
|
||||||
|
|
||||||
[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }
|
[[ $# -eq 1 ]] || {
|
||||||
|
echo "${FUNCNAME[0]} function requires 1 argument"
|
||||||
sed "/$@/d" ~/.dirs > ~/.dirs1;
|
return 1
|
||||||
\mv ~/.dirs1 ~/.dirs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alias U='source ~/.dirs' # Update bookmark stack
|
sed "/$1/d" "${BASH_IT_DIRS_BKS?}" > "${BASH_IT_DIRS_BKS?}.new"
|
||||||
|
command mv "${BASH_IT_DIRS_BKS?}.new" "${BASH_IT_DIRS_BKS?}"
|
||||||
|
}
|
||||||
|
|
||||||
|
alias U='source "${BASH_IT_DIRS_BKS?}"' # Update bookmark stack
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue