My scripts for startup, dmenu, and the command line
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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