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.

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