-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsopen
More file actions
executable file
·97 lines (87 loc) · 2.18 KB
/
sopen
File metadata and controls
executable file
·97 lines (87 loc) · 2.18 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
#!/usr/bin/env bash
# README: this script required bash 4+ (it uses associative arrays, which are supported since bash 4)
# also search two lists, one is commands and the other is links
source ./secret_variables.sh
source ~/.bash_profile
# defaults
verbose="False"
list_links()
{
echo "Available links:"
iter=1
for key in "${!links[@]}"; do
echo "$iter. $key at (${links[$key]})"
((iter = iter+1))
done
}
list_players()
{
echo "Available command line players:"
iter=1
for key in "${!players[@]}"; do
echo "$iter. $key at (${players[$key]})"
((iter = iter+1))
done
}
help()
{
echo "sopen (special open) is a bash/shell script for Unix (incl. Mac) that opens a requested link name (which is a shortcut name defined by the user in the sopen executable file directly). "
echo
echo "Usage:\n> sopen <name>"
echo "options:"
echo "-h --help Display this help."
echo "-l --list Display available links (add more by editing the script)."
echo
}
function parse_params() {
local param
while [[ $# -gt 0 ]]; do
param="$1"
shift
case $param in
-h | --help)
help;
exit 0
;;
-l | --list)
list_links;
exit 0
;;
-V | --verbose)
verbose="True"
;;
*)
case $last_arg in
*)
echo "parameter was provided: $param"
target=$param
;;
esac
;;
esac
done
}
parse_params "$@"
if [ $verbose == "True" ]
then
echo "-------"
echo "verbose todo"
echo "-------"
fi
echo "${links[$target]}"
STR="${links[$target]}"
SUB='>'
if [[ "$STR" == *"$SUB"* ]]; then
STR2=$(echo "$STR" | sed 's/>//')
#echo "eval:"
#echo "$STR2"
if [ "${STR2:0:2}" == "cd" ]; then #this is a strange necessary hack right now
echo -e "Opening in a subshell with command: $STR2\nDo exit to quit this subshell and return here."
bash -c "exec bash --init-file <(echo \"$STR2\")"
else
eval "$STR2" #this works for a command like bitwarden but not for cd? What? TODO
fi
else
echo "open:"
open "${links[$target]}"
fi