-
Notifications
You must be signed in to change notification settings - Fork 0
/
rot
executable file
·70 lines (59 loc) · 1.36 KB
/
rot
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
#!/usr/bin/env bash
env=`cat ~/.local/share/rotator/.rotator.json | jq -r .currentEnv`
use_tmux=false
while :; do
case $1 in
-m | --mark)
rotator --mark
break;;
-u | --unmark)
rotator --unmark
break;;
-s | --switch)
rotator --switch
break;;
-e | --env)
echo "You are in $env"
break;;
-n | --new)
rotator --new
break;;
-c | --clean)
rotator --clean
break;;
-t | --tmux)
use_tmux=true
break;;
-?*)
echo "Invalid argument"
break;;
?*)
cd $1
break;;
*)
break
esac
shift
done
env=`cat ~/.local/share/rotator/.rotator.json | jq -r .currentEnv`
selected=`cat ~/.local/share/rotator/.rotator.json | jq -r '.'$env' | keys[] as $k | $k' | fzf --header=$env --height=40% --reverse`
if [[ -z $selected ]]; then
echo 'No directory selected'
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
dir=`cat ~/.local/share/rotator/.rotator.json | jq -r .$env.$selected`
if [ "$use_tmux" = true ]; then
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $dir
exit 0
fi
if ! tmux has-session -t $selected_name 2> /dev/null; then
tmux new-session -ds $selected_name -c $dir
fi
tmux switch-client -t $selected_name
else
echo $dir
cd $dir
fi