-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdsf
executable file
·39 lines (33 loc) · 908 Bytes
/
dsf
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
#!/bin/bash
# dsf -- directory specific functions
#
# TL;DR
# - add a file called ".__" containing shell functions in some directory
# - those functions are now available only in that directory and below
#
# for more, see "dsf.mkd" in the same place you found this file, probably https://github.com/sitaramc/notes/blob/master/dsf.mkd
shopt -s inherit_errexit
set -euo pipefail
IFS=$'\n\t'
# set -x
# export PS4=':.$LINENO:'
__files() (
set +e
while [[ $PWD == $HOME/* ]]; do
[[ -f $PWD/.__ ]] && echo $PWD/.__
cd ..
done
[[ -f $HOME/.__ ]] && echo $HOME/.__
[[ -f /etc/.__ ]] && echo /etc/.__
)
# deal with help
[[ -z "${1:-}" ]] && set -- help
help() {
cat `__files` |
grep -E '^## ' | cut -c4-
}
die() { echo >&2 "$@"; exit 1; }
# actual functions get pulled in here
for __f in `__files`; do source $__f; done
[[ -n "${D:-}" ]] && set -x
"$@"