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.

325 lignes
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. 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. Select VPN
  54. Disable VPN
  55. Enable VPN
  56. VPN Status
  57. Rebind Keys
  58. Show calender
  59. Disable Bar
  60. Password
  61. Username
  62. Alternate password
  63. Download
  64. Enable Bar" | tr -d '\t' |
  65. dmenu -i -p "Actions")
  66. case $action in
  67. 'Play Music') mpc play ;;
  68. 'Pause Music') mpc pause ;;
  69. 'Toggle Music') mpc toggle ;;
  70. 'Rebind Keys') setup-xbindkeys;;
  71. 'Disable Bar') tmux set -g status off;;
  72. 'Enable Bar') tmux set -g status on;;
  73. 'Command') cmd;;
  74. 'Choose') chooser;;
  75. 'Command to clipboard') cmd_clip;;
  76. 'Username') username;;
  77. 'Password') password;;
  78. 'Alternate password') other_password;;
  79. 'Show calender') notify-send 'Calender' "\n\n$(cal)";;
  80. #This should check for an error code and confirm that download has started
  81. '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";;
  82. esac
  83. }
  84. do_search() {
  85. type=$(printf "Manual
  86. DDG
  87. Definition
  88. Godocs
  89. Mojeek
  90. Package
  91. Github" | tr -d '\t' | dmenu -i -p "Search")
  92. case "$type" in
  93. Manual) p=$(printf '' | dmenu -p 'man'); if [ -z $p ]; then exit; fi; st -t "Manual $p" -e man "$p";;
  94. Github) github;;
  95. Godocs) godoc;;
  96. DDG) ddg;;
  97. Package) package;;
  98. Definition) word=$(printf '' | dmenu -p 'word'); if [ -z "$word" ]; then exit; fi; st -e sh -lc "dict \"$word\" | less";;
  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