-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.sh
executable file
·47 lines (40 loc) · 1017 Bytes
/
index.sh
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
#!/usr/bin/env bash
# Get present script directory.
# - https://stackoverflow.com/a/246128/1413259
psd() {
z="${BASH_SOURCE[0]}"
if [ -h "$z" ]; then z="$(readlink "$z")"; fi
cd "$(dirname "$0")" && cd "$(dirname "$z")" && pwd
}
# Change the working directory, with shortcuts and listing.
extra-cd() {
# Setup config directory
local d="$HOME/.config/npm/extra-cd"
mkdir -p "$d"
# Process arguments
local l="0"
local a="$1"
local c="${a:0:1}"
local f="$d/${a:1}.txt"
if [[ "$1" == "--help" ]]; then
less "$(psd)/README.md"
elif [[ "$1" == "-" ]]; then
l="1" && popd > /dev/null
elif [[ "$c" == "+" ]]; then
if [[ "$2" == "" ]]; then pwd > "$f"; else echo "$2" > "$f"; fi
elif [[ "$c" == "-" ]]; then
rm -f "$f"
elif [[ "$c" == "=" ]]; then
l="1" && pushd $(cat "$f") > /dev/null
else
l="1" && pushd "$1" > /dev/null
fi
# List directory
if [[ "$l" == "1" ]]; then
ls --color --group-directories-first && echo
fi
}
# Change the working directory, with shortcuts and listing.
ecd() {
extra-cd "$@"
}