-
Notifications
You must be signed in to change notification settings - Fork 0
/
workspace.sh
68 lines (63 loc) · 1.59 KB
/
workspace.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
WORKSPACE=~/workspace
workspace() {
DIR=${1}
if [ ! "${DIR}" ]; then
error "<dir> arg is required"
return 1
fi
cd -P ${WORKSPACE}/${DIR}
if which conda &>/dev/null; then
conda deactivate
if conda info --envs | awk '{print $1}' | grep -q ^${DIR}$; then
conda activate ${DIR}
fi
fi
}
_workspace_completion() {
find ${WORKSPACE}/ -maxdepth 1 -type d,l | sed 's,^.*/,,g' | grep -v '^$' | grep ^${2}
}
complete -C _workspace_completion workspace
NOTES=~/workspace/notes
notes() {
local EDIT=false
local NOTE=""
while [ "$1" ]; do
case $1 in
-e | --edit )
EDIT=true
;;
* )
NOTE=$1
;;
esac
shift
done
if [ ! "$NOTE" ]; then
error "Missing note filename"
return 1
fi
NOTE=$NOTES/$NOTE
if [ -d $NOTE ]; then
for FILE in $(ls $NOTE); do
echo $1/$FILE
done
elif [ -f $NOTE ]; then
if [ "$EDIT" == "true" ]; then
vim $NOTE
else
cat $NOTE
echo
fi
else
error "\"$NOTE\" not found"
return 1
fi
}
_notes_completion() {
find ${NOTES}/ -maxdepth 1 -type f | sed 's,^.*/,,g' | grep -v '^$' | grep ^${2}
DIRS=$(find ${NOTES}/ -maxdepth 1 -type d,l | sed 's,^.*/,,g' | grep -v '^$' | grep ^${2})
for DIR in $DIRS; do
find ${NOTES}/${DIR}/ -maxdepth 1 -type f | sed 's,^.*/,,g' | grep -v '^$' | grep ^${2} | sed 's,^,'$DIR'/,'
done
}
complete -C _notes_completion notes