forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirs.plugin.bash
More file actions
122 lines (102 loc) · 2.82 KB
/
dirs.plugin.bash
File metadata and controls
122 lines (102 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# shellcheck shell=bash
# Directory stack navigation:
#
# Add to stack with: pu /path/to/directory
# Delete current dir from stack with: po
# Show stack with: d
# Jump to location by number.
cite about-plugin
about-plugin 'directory stack navigation'
# Show directory stack
alias d="dirs -v -l"
# Change to location in stack by number
alias 1="pushd"
alias 2="pushd +2"
alias 3="pushd +3"
alias 4="pushd +4"
alias 5="pushd +5"
alias 6="pushd +6"
alias 7="pushd +7"
alias 8="pushd +8"
alias 9="pushd +9"
# Clone this location
alias pc='pushd "${PWD}"'
# Push new location
alias pu="pushd"
# Pop current location
alias po="popd"
function dirs-help() {
about 'directory navigation alias usage'
group 'dirs'
echo "Directory Navigation Alias Usage"
echo
echo "Use the power of directory stacking to move"
echo "between several locations with ease."
echo
echo "d : Show directory stack."
echo "po : Remove current location from stack."
echo "pc : Adds current location to stack."
echo "pu <dir>: Adds given location to stack."
echo "1 : Change to stack location 1."
echo "2 : Change to stack location 2."
echo "3 : Change to stack location 3."
echo "4 : Change to stack location 4."
echo "5 : Change to stack location 5."
echo "6 : Change to stack location 6."
echo "7 : Change to stack location 7."
echo "8 : Change to stack location 8."
echo "9 : Change to stack location 9."
}
# Add bookmarking functionality
# Usage:
: "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-${HOME}/.local/state}/bash_it/dirs}"
if [[ -f "${BASH_IT_DIRS_BKS?}" ]]; then
# shellcheck disable=SC1090
source "${BASH_IT_DIRS_BKS?}"
else
mkdir -p "${BASH_IT_DIRS_BKS%/*}"
if [[ -f ~/.dirs ]]; then
mv -vn ~/.dirs "${BASH_IT_DIRS_BKS?}"
# shellcheck disable=SC1090
source "${BASH_IT_DIRS_BKS?}"
else
touch "${BASH_IT_DIRS_BKS?}"
fi
fi
alias L='cat "${BASH_IT_DIRS_BKS?}"'
# Goes to destination dir, otherwise stay in the dir
function G() {
about 'goes to destination dir'
param '1: directory'
example '$ G ..'
group 'dirs'
cd "${1:-${PWD}}" || return
}
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 "/$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'
param '1: bookmark name'
example '$ R mybkmrk'
group 'dirs'
[[ $# -eq 1 ]] || {
echo "${FUNCNAME[0]} function requires 1 argument"
return 1
}
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