My scripts for startup, dmenu, and the command line
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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