-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbm3
executable file
·46 lines (38 loc) · 1.63 KB
/
bm3
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
#!/usr/bin/bash
file_path="$HOME/media/random/bm3/bm3_data.txt"
delete_entry() {
selected_line=$(cat "$file_path" | sed '1!G;h;$!d' | rofi -dmenu -theme-str 'listview {columns: 2;} window {width:64%;}' -width 60 -location 0)
[ -n "$selected_line" ] && sed -i "/$(echo "$selected_line" | sed 's/[\/&]/\\&/g')/d" "$file_path"
cd "$HOME/media/random/bm3"; git add -A; git commit -m 'bm3'
}
save_info() {
echo "$(date '+%Y-%m-%d %H:%M:%S'): $1" >> "$file_path"
cd "$HOME/media/random/bm3"; git add -A; git commit -m 'bm3'
}
select_info() {
selected_line=$(cat "$file_path" | sed '1!G;h;$!d' | rofi -dmenu -theme-str 'listview {columns: 2;} window {width:64%;}' | sed 's/^.\{21\}//')
[ -n "$selected_line" ] && entry=$(echo -n "$selected_line") && echo "$selected_line" | grep "https://" && {
choice=$(echo -e "Yes\nNo" | rofi -dmenu -p "do you want to open in browser?" -i)
case $choice in
"Yes") firefox "$(echo $entry | grep -o 'https://[^ ]*')" && exit 0 ;;
"No") echo -n "$entry" | xclip -selection clipboard ;;
esac
} || {
echo -n "$entry" | xclip -selection clipboard
test $(echo "$entry" | wc -c) -gt 20 && rofi -e "$entry"
}
}
options=("show (x)" "save (b)" "delete (d)")
selected_option=$(printf "%s\n" "${options[@]}" | rofi -dmenu -p "(" -theme-str 'window {width:8%;}' )
case $selected_option in
"save (b)")
new_info=$(rofi -dmenu -p "enter information to save" )
[ -n "$new_info" ] && save_info "$new_info"
;;
"show (x)")
select_info
;;
"delete (d)")
delete_entry
;;
esac