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.

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