plugin/dirs: `shfmt` && `shellcheck`

pull/1904/head
John D Pell 2021-09-20 13:10:54 -07:00
parent 68f0cd6ebf
commit 5c8ef51dfb
2 changed files with 58 additions and 52 deletions

View File

@ -88,6 +88,7 @@ plugins/available/basher.plugin.bash
plugins/available/blesh.plugin.bash
plugins/available/cmd-returned-notify.plugin.bash
plugins/available/direnv.plugin.bash
plugins/available/dirs.plugin.bash
plugins/available/docker-machine.plugin.bash
plugins/available/git.plugin.bash
plugins/available/go.plugin.bash

View File

@ -1,3 +1,4 @@
# shellcheck shell=bash
# Directory stack navigation:
#
# Add to stack with: pu /path/to/directory
@ -59,12 +60,12 @@ function dirs-help() {
# Usage:
: "${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
if [[ -f "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-~/.local/state}/Bash_it/dirs}" ]]; then
# shellcheck disable=SC1090
source "$BASH_IT_DIRS_BKS"
elif [[ -f ~/.dirs ]]
then
elif [[ -f ~/.dirs ]]; then
mv -vn ~/.dirs "$BASH_IT_DIRS_BKS"
# shellcheck disable=SC1090
source "$BASH_IT_DIRS_BKS"
else
touch "$BASH_IT_DIRS_BKS"
@ -73,42 +74,46 @@ fi
alias L='cat "$BASH_IT_DIRS_BKS"'
# Goes to destination dir, otherwise stay in the dir
function G()
{
function G() {
about 'goes to destination dir'
param '1: directory'
example '$ G ..'
group 'dirs'
cd "${1:-${PWD}}" ;
cd "${1:-${PWD}}" || return
}
function 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; }
sed "/$@/d" "$BASH_IT_DIRS_BKS" > ~/.dirs1;
\mv ~/.dirs1 "$BASH_IT_DIRS_BKS";
echo "$@"=\""${PWD}"\" >> "$BASH_IT_DIRS_BKS";
source "$BASH_IT_DIRS_BKS" ;
[[ $# -eq 1 ]] || {
echo "${FUNCNAME[0]} function requires 1 argument"
return 1
}
function R()
{
sed "/$1/d" "$BASH_IT_DIRS_BKS" > ~/.dirs1
command mv ~/.dirs1 "$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'
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" "$BASH_IT_DIRS_BKS" > ~/.dirs1;
\mv ~/.dirs1 "$BASH_IT_DIRS_BKS";
sed "/$1/d" "$BASH_IT_DIRS_BKS" > ~/.dirs1
\mv ~/.dirs1 "$BASH_IT_DIRS_BKS"
}
alias U='source "$BASH_IT_DIRS_BKS"' # Update bookmark stack