This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rofi-shortcut.sh
executable file
·174 lines (155 loc) · 3.71 KB
/
rofi-shortcut.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# a script for output the shortcuts in the active window
#!/usr/bin/env bash
# need to install: xdotool , rofi , xsel
# only [ false or true ]
Run_shortcut=false
Debug_active=false
readonly window=$(xdotool getwindowfocus getwindowname)
readonly wn=$(xdotool getactivewindow)
readonly Keys_Dir="$HOME/.config/rofi/keys"
readonly Keys=$(ls $Keys_Dir|cut -d "." -f 1)
#readonly Num_Keys=$(ls $Keys_Dir|wc -l)
# if you have tmux
if [ -f /usr/bin/tmux ]
then
readonly if_tmux_acti=$(tmux list-panes -F '#{pane_active} #{pane_current_command}'|grep "1"|cut -d " " -f 2 )
fi
# a debug message
#echo "Debug 0"
terminal(){
if [ -f /usr/bin/kitty ]
then
kitty="Kitty\nShortcuts for "
else
kitty=""
fi
if [[ "$window" == *"tmux"* ]]
then
re="tmux\n"
#Terminal with tmux
re+="Shortcuts for "
case $if_tmux_acti in
# *"$Custom"*) re="$Custom";;
*"vim"*) re+="Vim";;
*) re+="nothing";;
esac
else
#Terminal default
ter_win=($(echo $window|tr "-" "\n"))
case ${ter_win[1]} in
# *"$Custom"*) re="$Custom";;
*"vim"*) re="Vim";;
*) re="nothing";;
esac
fi
if [[ "$re" == *"nothing" ]]
then
re=$(echo -e $re|head -n -1)
fi
echo $kitty$re
# return $re
}
#cat the shortcuts file
second_frame(){
# a debug message
# echo "Debug 2"
Program=$(echo $3)
Path_Pro=$(echo $Keys_Dir/$Program".txt")
if $Debug_active
then
echo -e "Debug file name: " $Path_Pro
fi
string_keys="{ back to menu \n"
string_keys+=$(cat $Path_Pro)
echo -e "${string_keys}"
}
#it doesn't work
run_short_func(){
if $Run_shortcut
then
#special thank go to "https://github.com/raphaelfournier/rofi-modi-snippets"
coproc(xdotool key $2)
fi
exit0
}
# This Fuction is for output all Shortcuts Files(all support programms)
search_key(){
echo -e "{ back to menu"
echo $Keys|tr ' ' '\n'|sed "s/^/Shortcuts for /g"
}
#jump from 2.menu to the 1.menu
go_back(){
main
}
#select programm window
main(){
# a debug message
# echo "Debug 1"
Output_Main="All Shortcuts \n"
# Output_Main+="Shortcuts for Xfce4 \"Display Manager\"\n"
Output_Main+="Shortcuts for "
case $window in
# *"$Custom"*) Output_Main+="$Custom";;"
*"Ardour"*) Output_Main+="Ardour";;
*"Arduino"*) Output_Main+="Arduino";;
*"Atom"*) Output_Main+="Atom";;
*"Audacity"*) Output_Main+="Audacity";;
*"Blender"*) Output_Main+="Blender";;
*"Burp"*) Output_Main+="Burp";;
*"Chrome"*) Output_Main+="Chrome";;
*"Chromium"*) Output_Main+="Chromium";;
*"Code - OSS"*) Output_Main+="VSCode";;
*"darktable"*) Output_Main+="Darktable";;
*"Firefox"*) Output_Main+="Firefox\n" && Next="firefox";;
*"gedit"*) Output_Main+="Gedit";;
*"GNU Image Manipulation Program"*) Output_Main+="Gimp";;
*"GIMP"*) Output_Main+="Gimp";;
*"Inkscape"*) Output_Main+="Inkscape";;
*"Kdenlive"*) Output_Main+="Kdenlive";;
*"KiCad"*) Output_Main+="Kicad";;
*"Krita"*) Output_Main+="Krita";;
*"mpv"*) Output_Main+="mpv";;
*"REAPER"*) Output_Main+="Reaper";;
*"Typora"*) Output_Main+="Typora";;
*"Zrythm"*) Output_Main+="Zrythm";;
*"Terminal"*) Output_Main+=$(terminal);;
*"tmux"*) Output_Main+=$(terminal);;
*) Output_Main=$(echo -e $Output_Main|head -n -1);;
esac
if [[ "$Next" == *"firefox"* ]]
then
Output_Main+="Shortcuts for "
Output_Main+=$(echo $window|grep -o "YouTube")
fi
if [[ "$Output_Main" == *"Shortcuts for " ]]
then
Output_Main=$(echo -e $Output_Main|head -n -1)
fi
Output_Main+=" \n"
if $Debug_active
then
echo -e "Debug window_name: " $window
fi
echo -e "${Output_Main}"
}
if $Debug_active
then
echo -e "Debug args: " $@
fi
if [[ "$@" ]]
then
if [[ "$1" == "->"* ]]
then
run_short_func $1 $2
elif [[ "$1" == "All"* ]]
then
search_key
elif [[ "$1" == "{"* ]]
then
go_back $@
else
second_frame $1 $2 $3
fi
else
main
fi