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.

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