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.

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