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.

188 lignes
4.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. 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 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. Command
  36. Command to clipboard
  37. Search github
  38. Search ddg
  39. Search godoc
  40. Select VPN
  41. Disable VPN
  42. Enable VPN
  43. VPN Status
  44. Rebind Keys
  45. Disable Bar
  46. Enable Bar" | tr -d '\t' |
  47. dmenu -i -p "Actions")
  48. case $action in
  49. 'Play Music') mpc play ;;
  50. 'Pause Music') mpc pause ;;
  51. 'Toggle Music') mpc toggle ;;
  52. 'Rebind Keys') setup-xbindkeys;;
  53. 'Disable Bar') tmux set -g status off;;
  54. 'Enable Bar') tmux set -g status on;;
  55. 'Search github') github;;
  56. 'Search godoc') godoc;;
  57. 'Search ddg') ddg;;
  58. 'Command') cmd;;
  59. 'Command to clipboard') cmd_clip;;
  60. esac
  61. }
  62. screenshot() {
  63. method=$(printf "clipboard
  64. file
  65. both" |
  66. dmenu -i -p "Screenshot")
  67. if [ $method = "file" ]; then
  68. scrot --note "-f 'LiterationSans Nerd Font Book/11' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'"\
  69. -s ~/Pictures/screenshots/screenshot-%Y-%m-%d_$wx$h.png
  70. fi
  71. if [ $method = "clipboard" ]; then
  72. scrot --note "-f 'LiterationSans Nerd Font Book/11' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'"\
  73. -s ~/Pictures/screenshots/screenshot-%Y-%m-%d_$wx$h.png\
  74. -e "xclip $f; rm $f"
  75. fi
  76. if [ $method = "both" ]; then
  77. scrot --note "-f 'LiterationSans Nerd Font Book/11' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'"\
  78. -s ~/Pictures/screenshots/screenshot-%Y-%m-%d_$wx$h.png\
  79. -e "xclip $f;"
  80. fi
  81. }
  82. search_type() {
  83. search_string="$(printf "New window\nBookmarks\nHistory" | dmenu -p "$1")"
  84. search_mode='tab'
  85. case "$search_string" in
  86. 'New window') search_mode='window'; search_string=$(printf '' | dmenu -p "new $1");;
  87. 'Bookmarks');;
  88. 'History') ;;
  89. # *) printf "Invalid argument";;
  90. esac
  91. printf "$search_string|$search_mode"
  92. }
  93. brave_search() {
  94. search_prefix="$1"
  95. search_info="$(search_type "$2")"
  96. search_string=$(printf "$search_info" | cut -d'|' -f1)
  97. search_mode=$(printf "$search_info" | cut -d'|' -f2)
  98. if [ -z "$search_string" ]; then exit; fi
  99. new_string=$(rawurlencode "$search_string")
  100. search="$search_prefix$new_string"
  101. case "$search_mode" in
  102. tab) $browser_cmd "$search";;
  103. window) $browser_new_cmd "$search";;
  104. esac
  105. }
  106. rawurlencode() {
  107. #Takes the first argument and encodes it
  108. search_string="$1"
  109. string_length=$(expr length "$search_string")
  110. char=''; new_string='';
  111. i=1
  112. while [ $i -le $string_length ]
  113. do
  114. char=$(expr substr "$search_string" $i 1)
  115. # new_string="$new_string$(rawurlencode "$char")"
  116. case "$char" in
  117. [-_.~a-zA-Z0-9] ) new_string="$new_string$char";;
  118. * ) new_string="$new_string%$(printf '%%%02x' "'$char")";;
  119. esac
  120. i=$(expr $i + 1)
  121. done
  122. printf "$new_string"
  123. }
  124. ddg() {
  125. brave_search "https://duckduckgo.com/?q=" "ddg"
  126. }
  127. github() {
  128. brave_search "https://github.com/search?q=" "github"
  129. }
  130. godoc() {
  131. brave_search "https://golang.org/pkg/" "godoc"
  132. }
  133. manual() {
  134. search=$(printf '' | dmenu -p 'manual')
  135. result=$(man "$search")
  136. printf "$result" | zathura -
  137. # notify-send -u low -t 0 "Manual" "$result"
  138. }
  139. goinfo() {
  140. #Maybe this can also show recent searches
  141. search=$(printf '' | dmenu -p 'goinfo')
  142. result=$(go doc "$search")
  143. notify-send -u low -t -1 "Go documentation" "$result"
  144. }
  145. cmd() {
  146. sh -c "$(printf '' | dmenu -i -p 'cmd')"
  147. }
  148. cmd_clip() {
  149. value=$(cmd)
  150. show_value="$(expr substr "$value" 1 200)\n..."
  151. notify-send -u low -t 2000 "Items cliped" "$show_value"
  152. printf "%s" "$value" | xclip -selection clipboard
  153. }
  154. case $1 in
  155. launch) launch;;
  156. action) action;;
  157. cmd) action;;
  158. cmd_clip) cmd_clip;;
  159. ddg) ddg;;
  160. github) github;;
  161. godoc) godoc;;
  162. goinfo) goinfo;;
  163. manual) manual;;
  164. *) printf "Invalid argument";;
  165. esac