My scripts for startup, dmenu, and the command line
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
8.5 KiB

  1. #!/bin/sh
  2. browser_cmd="brave-browser"
  3. browser_new_cmd="brave-browser --new-window"
  4. launch() {
  5. app=$(printf "Notes
  6. Files
  7. Edit
  8. Editor
  9. Open
  10. Terminal
  11. Multiplexer
  12. LBRY
  13. Chat
  14. Music
  15. Browser
  16. Hidden browser
  17. Email
  18. Page
  19. Go page
  20. Package info
  21. Play clipboard
  22. Play downloads
  23. Processes" | tr -d '\t' |
  24. dmenu -i -p "Launcher")
  25. case $app in
  26. Notes) st -t "Notes" -e vim "+cd ~/Notes/text" "+CtrlP";;
  27. Files) st -t "Files" -e sh -lc nnn;;
  28. Edit) editor;;
  29. Editor) st -t "Editor" -e vim "+CtrlPMRUFiles";;
  30. Open) opener;;
  31. Terminal) st -t "Terminal";;
  32. Page) pages pager "$(printf "1\n2\n3\n" | dmenu -p 'page')";;
  33. Multiplexer) st -t "Multiplexer" -e tmux attach-session -t 0 || st -t "Multiplexer" -e tmux new-session -s 0;;
  34. LBRY) lbry;;
  35. 'Go page') num=$(go_page); pages pager $num;;
  36. Chat) element-desktop;;
  37. Music) st -t "Music" -e ncmpcpp;;
  38. Browser) $browser_cmd;;
  39. 'Hidden browser') $browser_cmd --incognito;;
  40. Email) $browser_cmd mail.protonmail.com/login;;
  41. 'Play clipboard') mpv "$(xclip -o -selection clipboard)";;
  42. 'Play downloads') mpv "$HOME/Downloads/tmp/$(ls ~/Downloads/tmp/ | dmenu -i -l 10 -p 'play')";;
  43. Processes) st -t "Processes" -e htop;;
  44. esac
  45. }
  46. action() {
  47. action=$(printf "Toggle Music
  48. Pause Music
  49. Play Music
  50. Command
  51. Command to clipboard
  52. Choose
  53. Select VPN
  54. Disable VPN
  55. Enable VPN
  56. VPN Status
  57. Rebind Keys
  58. Show calender
  59. Disable Bar
  60. Password
  61. Username
  62. Alternate password
  63. Download
  64. Enable Bar" | tr -d '\t' |
  65. dmenu -i -p "Actions")
  66. case $action in
  67. 'Play Music') mpc play ;;
  68. 'Pause Music') mpc pause ;;
  69. 'Toggle Music') mpc toggle ;;
  70. 'Rebind Keys') setup-xbindkeys;;
  71. 'Disable Bar') tmux set -g status off;;
  72. 'Enable Bar') tmux set -g status on;;
  73. 'Command') cmd;;
  74. 'Choose') chooser;;
  75. 'Command to clipboard') cmd_clip;;
  76. 'Username') username;;
  77. 'Password') password;;
  78. 'Alternate password') other_password;;
  79. 'Show calender') notify-send 'Calender' "\n\n$(cal)";;
  80. #This should check for an error code and confirm that download has started
  81. 'Download') youtube-dl --no-progress -o "$HOME/Downloads/tmp/%(title)s.%(ext)s" "$(xclip -selection clipboard -o)"; notify-send -u low -t 3000 "Download complete";;
  82. esac
  83. }
  84. login() {
  85. choice=$(printf "Auto
  86. Username
  87. Password
  88. Alternate
  89. Show
  90. Edit" | tr -d '\t' | dmenu -i -p "login")
  91. case $choice in
  92. Username) username;;
  93. Password) password;;
  94. Alternate) other_password;;
  95. Show) show_password;;
  96. esac
  97. }
  98. do_search() {
  99. type=$(printf "Manual
  100. DDG
  101. Definition
  102. Godocs
  103. Mojeek
  104. Package
  105. Github" | tr -d '\t' | dmenu -i -p "Search")
  106. case "$type" in
  107. Manual) p=$(printf '' | dmenu -p 'man'); if [ -z $p ]; then exit; fi; st -t "Manual $p" -e man "$p";;
  108. Github) github;;
  109. Godocs) godoc;;
  110. DDG) ddg;;
  111. Package) package;;
  112. Definition) word=$(printf '' | dmenu -p 'word'); if [ -z "$word" ]; then exit; fi; st -e sh -lc "dict \"$word\" | less";;
  113. esac
  114. }
  115. package() {
  116. type=$(printf "search\ninfo" | dmenu -p 'package')
  117. if [ -z "$type" ]; then
  118. exit
  119. elif [ "$type" = "info" ]; then
  120. s=$(dmenu_path | dmenu -i -p 'package info')
  121. st -e sh -lc "apt-cache show $s"
  122. else
  123. s=$(dmenu -i -p 'package search')
  124. st -e sh -lc "apt search \"$s\""
  125. fi
  126. }
  127. editor() {
  128. #handle spacing in filenames bug
  129. file=$(mru list | dmenu -i -l 10 -p 'edit file')
  130. if [ -z "$file" ]; then exit; fi
  131. first=$(printf "$file" | head -n1 -)
  132. d=$(dirname "$first")
  133. files=$(printf "$file" | tr '\n' ' ')
  134. printf "files: $files"
  135. st -t 'Editor' -e vim "+cd $d" $files
  136. }
  137. opener() {
  138. mru list | dmenu -i -l 20 -p 'open' | while read f; do xdg-open "$f"; done
  139. }
  140. screenshot() {
  141. method=$(printf "clipboard
  142. file
  143. both" |
  144. dmenu -i -p "Screenshot")
  145. if [ $method = "file" ]; then
  146. scrot --note "-f 'LiterationSans Nerd Font Book/11' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'"\
  147. -s ~/Pictures/screenshots/screenshot-%Y-%m-%d_$wx$h.png
  148. fi
  149. if [ $method = "clipboard" ]; then
  150. scrot --note "-f 'LiterationSans Nerd Font Book/11' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'"\
  151. -s ~/Pictures/screenshots/screenshot-%Y-%m-%d_$wx$h.png\
  152. -e "xclip $f; rm $f"
  153. fi
  154. if [ $method = "both" ]; then
  155. scrot --note "-f 'LiterationSans Nerd Font Book/11' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'"\
  156. -s ~/Pictures/screenshots/screenshot-%Y-%m-%d_$wx$h.png\
  157. -e "xclip $f;"
  158. fi
  159. }
  160. search_type() {
  161. search_string="$(printf "New window\nBookmarks\nHistory" | dmenu -p "$1")"
  162. search_mode='tab'
  163. case "$search_string" in
  164. 'New window') search_mode='window'; search_string=$(printf '' | dmenu -p "new $1");;
  165. 'Bookmarks');;
  166. 'History') ;;
  167. # *) printf "Invalid argument";;
  168. esac
  169. printf "$search_string|$search_mode"
  170. }
  171. brave_search() {
  172. search_prefix="$1"
  173. search_info="$(search_type "$2")"
  174. search_string=$(printf "$search_info" | cut -d'|' -f1)
  175. search_mode=$(printf "$search_info" | cut -d'|' -f2)
  176. if [ -z "$search_string" ]; then exit; fi
  177. new_string=$(rawurlencode "$search_string")
  178. search="$search_prefix$new_string"
  179. case "$search_mode" in
  180. tab) $browser_cmd "$search";;
  181. window) $browser_new_cmd "$search";;
  182. esac
  183. }
  184. rawurlencode() {
  185. #Takes the first argument and encodes it
  186. search_string="$1"
  187. string_length=$(expr length "$search_string")
  188. char=''; new_string='';
  189. i=1
  190. while [ $i -le $string_length ]
  191. do
  192. char=$(expr substr "$search_string" $i 1)
  193. # new_string="$new_string$(rawurlencode "$char")"
  194. case "$char" in
  195. [-_.~a-zA-Z0-9] ) new_string="$new_string$char";;
  196. * ) new_string="$new_string%$(printf '%%%02x' "'$char")";;
  197. esac
  198. i=$(expr $i + 1)
  199. done
  200. printf "$new_string"
  201. }
  202. ddg() {
  203. brave_search "https://duckduckgo.com/?q=" "ddg"
  204. }
  205. github() {
  206. brave_search "https://github.com/search?q=" "github"
  207. }
  208. godoc() {
  209. brave_search "https://golang.org/pkg/" "godoc"
  210. }
  211. manual() {
  212. search=$(printf '' | dmenu -p 'manual')
  213. result=$(man "$search")
  214. printf "$result" | enscript -p - | ps2pdf - | zathura -
  215. }
  216. goinfo() {
  217. #Maybe this can also show recent searches
  218. search=$(printf "Window\nNotify" | dmenu -p 'goinfo')
  219. case $search in
  220. Window) search=$(printf '' | dmenu -p 'goinfo'); result=$(go doc "$search"); infowindow "$result"; exit;;
  221. Notify) search=$(printf '' | dmenu -p 'goinfo'); result=$(go doc "$search"); notify-send -u low -t 0 "Go documentation" "$result"; exit;;
  222. esac
  223. result=$(go doc "$search"); notify-send -u low -t 0 "Go documentation" "$result";
  224. }
  225. go_page() {
  226. name=$(printf "1\n2\n3\n4" | dmenu -p "page name")
  227. go doc "$(printf "" | dmenu -p 'go doc search')" > /tmp/pages-$name
  228. printf "$name"
  229. }
  230. infowindow() {
  231. printf "$1" | enscript -p - | ps2pdf - | zathura -
  232. }
  233. cmd() {
  234. c="$(printf '' | dmenu -i -p 'cmd')"
  235. output=$( $c )
  236. notify-send -u low 'command output' "$output"
  237. }
  238. cmd_clip() {
  239. value=$(cmd)
  240. show_value="$(expr substr "$value" 1 200)\n..."
  241. notify-send -u low -t 2000 "Items cliped" "$show_value"
  242. printf "%s" "$value" | xclip -selection clipboard
  243. }
  244. sel_account() {
  245. account=$(
  246. find ~/.password-store/[!\.]* -type f |
  247. sed -e "s:$HOME/.password-store/::" -e "s:\.gpg::" |
  248. dmenu -p 'account'
  249. )
  250. if [ -z "$account" ]; then exit; fi
  251. }
  252. username() {
  253. account=$(sel_account)
  254. if [ -z "$account" ]; then exit; fi
  255. name=$(pass show "$account" | sed -n -e "s/^username: //p" |
  256. dmenu -p 'which username' | xclip -f -selection clipboard)
  257. if [ -z "$name" ]; then exit; fi
  258. notify-send -u low -t 2000 "username copied" "$account: $name"
  259. }
  260. password() {
  261. rm prompt-login-*
  262. touch /tmp/prompt-login-$$
  263. account=$(find ~/.password-store/[!\.]* -type f |
  264. sed -e "s:$HOME/.password-store/::" -e "s:\.gpg::" |
  265. dmenu -p 'which service')
  266. pass -c $account
  267. notify-send -u low -t 1000 'password copied' "Copied $account"
  268. }
  269. other_password() {
  270. account=$(sel_account)
  271. name=$(pass show "$account" | sed -n -e "s/^username: //p" |
  272. dmenu -p 'which user password')
  273. if [ -z "$name" ]; then exit; fi
  274. pass show $account | sed "/^$/,/^username: $name/ { /^$/n }" | head -n1 | tr -d '\n' | xclip -selection clipboard
  275. notify-send -u low -t 2000 "password copied" "$account: $name"
  276. }
  277. show_password() {
  278. account=$(sel_account)
  279. info=$(pass show "$account")
  280. st -e sh -lc "printf '$info' | less"
  281. }
  282. edit_password() {
  283. account=$(sel_account)
  284. if [ -z "$account" ]; then exit; fi
  285. error=$(st -e pass edit "$account" 2>&1)
  286. if [ -n "$error" ]; then notify-send -u low -t 3000 "password edit error" "$error"; fi
  287. }
  288. chooser() {
  289. f=$(mru list | dmenu -i -l 20 -p 'choose file')
  290. if [ -z "$f" ]; then exit; fi
  291. c=$(dmenu_path | dmenu -i -p 'operation')
  292. if [ -z $c ]; then exit; fi
  293. $c "$f"
  294. }
  295. vpn() {
  296. ls
  297. }
  298. case $1 in
  299. launch ) launch;;
  300. action) action;;
  301. cmd) cmd;;
  302. cmd_clip) cmd_clip;;
  303. login) login;;
  304. search) do_search;;
  305. open) opener;;
  306. choose) chooser;;
  307. vpn) vpn;;
  308. *) printf "Invalid argument";;
  309. esac