dot_bashrc 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585
  1. ## Copyright © 2018, 2019, 2020, 2021, 2022, 2023, 2024 Oleg Pykhalov <go.wigust@gmail.com>
  2. ## Released under the GNU GPLv3 or any later version.
  3. if [ -f "/etc/skel/.bashrc" ]
  4. then
  5. # Load the skel profile's settings.
  6. source "/etc/skel/.bashrc"
  7. fi
  8. if [ -f "$HOME/.bash_vterm" ] && [[ $INSIDE_EMACS == vterm ]]
  9. then
  10. source "$HOME/.bash_vterm"
  11. fi
  12. if [ -f "$HOME/.bash_aliases" ]
  13. then
  14. # Load the Bash aliases and functions.
  15. source "$HOME/.bash_aliases"
  16. fi
  17. if [ -f "$HOME/.bash_guix" ]
  18. then
  19. source "$HOME/.bash_guix"
  20. fi
  21. function dmesg()
  22. {
  23. if [[ -z ${@:1} ]] && [[ -e "${HOME}/.guix-profile/bin/spacer" ]]
  24. then
  25. sudo /run/current-system/profile/bin/dmesg \
  26. --reltime \
  27. --human \
  28. --nopager \
  29. --decode \
  30. --ctime \
  31. --follow \
  32. --color=always \
  33. | "${HOME}/.guix-profile/bin/spacer"
  34. else
  35. sudo /run/current-system/profile/bin/dmesg
  36. fi
  37. }
  38. alias ,h="${BROWSER} ~/.guix-profile/share/doc/concise-gnu-bash/concise-gnu-bash.pdf"
  39. alias ,c='command'
  40. # Count number of code lines
  41. alias ,l='tokei'
  42. # Show Git repository statics
  43. alias ,g='onefetch'
  44. alias rm="rm -i"
  45. alias cp="cp -i"
  46. alias mv="mv -i"
  47. alias mtr="sudo mtr --show-ips --aslookup"
  48. alias xclipp='xclip -selection secondary'
  49. alias svg=xdot
  50. alias hosts='hosts --auto-sudo'
  51. alias log='sudo lnav /var/log'
  52. alias lsns='lsns --notruncate --output-all'
  53. alias goaccess='goaccess --log-format=COMBINED'
  54. alias catj=gron
  55. alias sqlite-visualize=sqleton
  56. alias tree="tree --dirsfirst -C"
  57. alias free="free -mht"
  58. alias psc='ps xawf -eo pid,user,cgroup,args'
  59. alias markdown-github=grip
  60. alias iostat='iostat -xm 2'
  61. alias dhall-to-yaml='dhall-to-yaml --omit-empty'
  62. alias noise-brown="mpv --no-resume-playback --loop '/srv/video/metube/Smoothed Brown Noise.webm'"
  63. mem()
  64. {
  65. cat <<EOF
  66. The top 5 applications using most RAM:
  67. $(ps -eo pid,%mem,cmd --sort=-%mem | head -n 6)
  68. EOF
  69. }
  70. httping()
  71. {
  72. case "$1" in
  73. majordomo*)
  74. command httping -s --colors https://www.majordomo.ru
  75. ;;
  76. *)
  77. command httping -s --colors "$@"
  78. ;;
  79. esac
  80. }
  81. emacs()
  82. {
  83. case "$1" in
  84. signals)
  85. "$BROWSER" https://emacs.stackexchange.com/a/44087
  86. ;;
  87. tty)
  88. emacs -nw -Q "${@:2}"
  89. ;;
  90. *)
  91. command emacs "$@"
  92. esac
  93. }
  94. emc()
  95. {
  96. # Setting TERM is required to fix colors in tmux running inside Alacritty.
  97. TERM=xterm-256color command emacsclient --create-frame --tty "$@"
  98. }
  99. guile()
  100. {
  101. (
  102. if [ "$INSIDE_EMACS" == "vterm" ]
  103. then
  104. unset INSIDE_EMACS
  105. fi
  106. case "$1" in
  107. wisp)
  108. exec -a "$0" guile -x .w --language=wisp "${@:2}"
  109. ;;
  110. *)
  111. exec -a "$0" guile "$@"
  112. ;;
  113. esac
  114. )
  115. }
  116. cat()
  117. {
  118. if [[ "${*:-1}" == /proc/*/environ ]]
  119. then
  120. command cat "${@: -1}" | tr '\000' '\n'
  121. elif [[ "${*:-1}" == *.md ]]
  122. then
  123. command glow "$@"
  124. else
  125. command cat "$@"
  126. fi
  127. }
  128. benchmark()
  129. {
  130. hyperfine "$@"
  131. }
  132. lsd()
  133. {
  134. if [ "$INSIDE_EMACS" == "vterm" ]
  135. then
  136. exa --all --long "$@"
  137. else
  138. ls "$@"
  139. fi
  140. }
  141. if [ -f "$HOME/.guix-profile/etc/profile.d/autojump.sh" ]
  142. then
  143. source "$HOME/.guix-profile/etc/profile.d/autojump.sh"
  144. fi
  145. # http://puzan.info/linux/2014-05-14-direnv.html
  146. if [ -f "$HOME/.guix-profile/bin/direnv" ]
  147. then
  148. eval "$(direnv hook bash)"
  149. fi
  150. man_in_emacs()
  151. {
  152. emacsclient --eval "(man \"$1\")"
  153. }
  154. man_to_pdf()
  155. {
  156. man -t "$1" | ps2pdf - "$1.pdf"
  157. }
  158. stat_link()
  159. {
  160. stat --format=%N "$@"
  161. }
  162. # Origin <https://www.fsf.org/blogs/directory/the-free-software-directory-needs-you-irc-meetups-every-friday-1>.
  163. #
  164. # Every Friday at 12:00-15:00 EDT (16:00 to 19:00 UTC)
  165. # meet on IRC in the #fsf channel on irc.freenode.org
  166. date_fsf()
  167. {
  168. date --date='TZ="America/New_York" 12:00 this Fri'
  169. }
  170. cl()
  171. {
  172. echo "$(tput cols)x$(tput lines)"
  173. }
  174. alias bedtime='sudo loginctl suspend'
  175. alias aria2c='aria2c --seed-time=0'
  176. ihs()
  177. {
  178. GUILE_INSTALL_LOCALE=0 \
  179. GUIX_BUILD_OPTIONS='' \
  180. IHS_USER=pyhalov \
  181. IHS_PASS="$(pass show majordomo/private/hms/pyhalov)" \
  182. CVM_USER=cron \
  183. CVM_PASS="$(pass show majordomo/private/cvm/cron)" \
  184. command ihs "$@"
  185. }
  186. if [[ -e "${HOME}/.bash.d/nix.bash" ]]
  187. then
  188. source "${HOME}/.bash.d/nix.bash"
  189. fi
  190. rg()
  191. {
  192. case "$1" in
  193. edit)
  194. last_command="$(history -w /dev/stdout | tail --lines=2 | head --lines=1)";
  195. if [[ "$last_command" =~ 'rg' ]] && [[ "$last_command" != *last_command* ]]
  196. then last_output="$(eval "$last_command")"
  197. emacsclient --no-wait +"$(echo "$last_output" | cut -d: -f 2)" "$(echo "$last_output" | cut -d: -f 1)"
  198. else
  199. emacsclient --no-wait "$@"
  200. fi
  201. stumpish emacsclient
  202. ;;
  203. *)
  204. command rg "$@"
  205. esac
  206. }
  207. # TODO: readlink could fail to enter `guix environment`
  208. # alias wi-pure-bash="env -i $(readlink $(which bash)) --noprofile --norc"
  209. # TODO: Escape window names with asterisks.
  210. # wi_x_resize_window ()
  211. # {
  212. # window_name=$(xwininfo | grep 'Window id' | awk '{ print $5 }')
  213. # xdotool search --name "$window_name" windowsize $1 $2
  214. # }
  215. iptables()
  216. {
  217. case "$1" in
  218. block)
  219. sudo --login command iptables -I INPUT -s "$2" -j DROP
  220. ;;
  221. --help)
  222. command iptables --help
  223. echo "\
  224. Extra commands:
  225. block block IP-ADDRESS on INPUT chain"
  226. ;;
  227. *)
  228. command sudo iptables "$@"
  229. ;;
  230. esac
  231. }
  232. ansible_host()
  233. {
  234. ansible --inventory "$1", "$1" --become --ask-become-pass "${@:2}"
  235. }
  236. yq()
  237. {
  238. command yq --width "$(tput cols)" "$@"
  239. }
  240. jc()
  241. {
  242. if [[ $# -eq 0 ]]
  243. then
  244. glow "https://github.com/kellyjonbrazil/jc"
  245. else
  246. command jc "$@"
  247. fi
  248. }
  249. jord_vm_ip()
  250. {
  251. gms vm ip "$1" | recsel -pip_address | awk '{ print $2 }'
  252. }
  253. jord_ansible_service_start()
  254. {
  255. vm="$(gms vm ip "$1" | recsel -pip_address | awk '{ print $2 }')"
  256. ansible --user sup --private-key="$HOME/.ssh/id_rsa_sup" --inventory "$vm", \
  257. "$vm" --module-name service --args "name=$2 state=started" \
  258. --become --ask-become-pass
  259. }
  260. jord_web_loadavg()
  261. {
  262. watch --color "seq -f 'web%gs' 15 37 | xargs guix environment -l $HOME/src/guile-loadavg/guix.scm -- $HOME/src/guile-loadavg/pre-inst-env loadavg weather"
  263. }
  264. parallel_curl()
  265. {
  266. parallel --will-cite -k 'printf "domain: %s\n" {1}; curl --max-time 10 -L -s -o /dev/null -w "ip-address: %{remote_ip}\nstatus_code: %{http_code}" {1}; printf "\n\n"' ::: "$@"
  267. }
  268. jord_web_account_check()
  269. {
  270. parallel --will-cite -k 'printf "domain: %s\n" {1}; curl --max-time 10 -L -s -o /dev/null -w "ip-address: %{remote_ip}\nstatus_code: %{http_code}" {1}; printf "\n\n"' \
  271. ::: "$(gms account website "$1" | recsel -pname | awk '{ print $2 }')"
  272. }
  273. guix_export_archive()
  274. {
  275. path="$1"
  276. destination="$2"
  277. guix archive --export -r "$path" \
  278. | ssh "$destination" guix archive --import
  279. }
  280. ssh_keygen_rsa()
  281. {
  282. file="$1"
  283. ssh-keygen -b 4096 -m pem -f "$HOME/.ssh/id_rsa_$file"
  284. }
  285. ssh_keygen_show_host_key()
  286. {
  287. ssh-keygen -lf <(ssh-keyscan -p 1022 "$1" 2>/dev/null)
  288. }
  289. activity()
  290. {
  291. ps -ef | awk '{ print $1 }' | sort | uniq | wc -l;
  292. }
  293. alias t5='TMOUT=5'
  294. alias close='TMOUT=5'
  295. # https://www.gnu.org/software/emacs/manual/html_node/efaq/Disabling-backups.html
  296. alias ls='ls -B -p --color=auto'
  297. if [ -f "$HOME/.nix-profile/share/bash-completion/completions/docker" ]
  298. then
  299. source "$HOME/.nix-profile/share/bash-completion/completions/docker"
  300. fi
  301. if [ -f "$HOME/.bash_tmp" ]
  302. then
  303. source "$HOME/.bash_tmp"
  304. fi
  305. alias bridge='bridge -color=always'
  306. alias ip='ip -color=always'
  307. jenkins_log()
  308. {
  309. job="$1"
  310. curl --silent --user "admin:$(pass show magnolia/jenkins/admin)" \
  311. "https://jenkins.wugi.info/job/$job/lastBuild/consoleText"
  312. }
  313. jenkins_jobs_list()
  314. {
  315. curl --silent --user "admin:$(pass show magnolia/jenkins/admin)" \
  316. https://jenkins.wugi.info/api/json/ \
  317. | jq -r '.jobs[] | [.name, .color] | @tsv'
  318. }
  319. jenkins_active_jobs()
  320. {
  321. jenkins-jobs | grep --color=no red_anime
  322. }
  323. grub_list_entries()
  324. {
  325. awk -F\" '$1=="menuentry " {print i++ " : " $2}' /boot/grub/grub.cfg
  326. }
  327. # https://github.com/jarun/Buku/wiki/Third-party-integration
  328. fb()
  329. {
  330. # save newline separated string into an array
  331. mapfile -t website <<< "$(buku -p -f 4 | column -ts$'\t' | fzf --multi)"
  332. # open each website
  333. for i in "${website[@]}"; do
  334. index="$(echo "$i" | awk '{print $1}')"
  335. buku -p "$index"
  336. buku -o "$index"
  337. done
  338. }
  339. guix()
  340. {
  341. guix_modules="$HOME/.local/share/chezmoi/dotfiles/guixsd/modules"
  342. guix_extra_modules=(
  343. "${HOME}/src/cgit.duckdns.org/guix/guix-wigust/guix"
  344. "${HOME}/src/gitlab.com/nonguix/nonguix"
  345. "${HOME}/src/gitlab.com/wigust/prometheus-shepherd-exporter"
  346. )
  347. case "$1" in
  348. manifest)
  349. case "$2" in
  350. apply)
  351. command guix package \
  352. -L "$HOME/.local/share/chezmoi/dotfiles/guixsd/modules" \
  353. --fallback \
  354. --manifest="$HOME/.local/share/chezmoi/dotfiles/manifests/$HOSTNAME.scm" "${@:3}"
  355. ;;
  356. build)
  357. command guix environment \
  358. -L "$HOME/.local/share/chezmoi/dotfiles/guixsd/modules" \
  359. --fallback \
  360. --manifest="$HOME/.local/share/chezmoi/dotfiles/manifests/$HOSTNAME.scm" "${@:3}" \
  361. -- sh -c 'exit 0'
  362. ;;
  363. esac
  364. ;;
  365. home)
  366. case "$2" in
  367. build)
  368. (
  369. cd "${HOME}/.local/share/chezmoi" || exit 1
  370. command guix home build \
  371. -L "$HOME/.local/share/chezmoi/dotfiles/guixsd/modules" \
  372. --fallback \
  373. "$HOME/.local/share/chezmoi/dotfiles/guixsd/home/${HOSTNAME}.scm" "${@:3}"
  374. )
  375. ;;
  376. switch)
  377. (
  378. cd "${HOME}/.local/share/chezmoi"
  379. guix_command=()
  380. if [[ "${PRE_INST_ENV:-FALSE}" == TRUE ]]
  381. then
  382. guix_command+=("${HOME}/src/git.savannah.gnu.org/git/guix/pre-inst-env")
  383. else
  384. guix_command+=("command")
  385. fi
  386. guix_command+=(
  387. guix home reconfigure
  388. )
  389. for module in "${guix_extra_modules[@]}"
  390. do
  391. guix_command+=("--load-path=${module}")
  392. done
  393. guix_command+=(
  394. --load-path="$guix_modules"
  395. --fallback
  396. )
  397. if [[ -n $allow_downgrades ]]
  398. then
  399. guix_command+=("--allow-downgrades")
  400. fi
  401. if [[ -n $fallback ]]
  402. then
  403. guix_command+=("--fallback")
  404. fi
  405. guix_command+=(
  406. "$HOME/.local/share/chezmoi/dotfiles/guixsd/home/${HOSTNAME}.scm"
  407. "${@:3}"
  408. )
  409. "${guix_command[@]}"
  410. )
  411. ;;
  412. esac
  413. ;;
  414. maintainer)
  415. mapfile -t output < <(git log --grep="gnu: Add" --format=%s --author=go.wigust@gmail.com)
  416. for line in "${output[@]}"
  417. do
  418. package="${line/gnu: Add /}"
  419. package="${package::-1}"
  420. case "$package" in
  421. *Revert*|*service*|premake4|perl-strictures-2|perl-role-tiny-2|emacs-cl-generic|emacs-seq|emacs-emms-player-simple-mpv|php-with-bcmath|shlomif-cmake-modules|go-github-com-muesli-reflow|go-github-com-emirpasic-gods-trees-binaryheap|nginx-socket-cloexec)
  422. printf ""
  423. ;;
  424. *go-github-com*)
  425. printf ""
  426. ;;
  427. *zabbix-agentd*)
  428. printf "zabbix-agentd\nzabbix-server\n"
  429. ;;
  430. *)
  431. echo "$package"
  432. ;;
  433. esac
  434. done
  435. ;;
  436. menu)
  437. {
  438. exec 3>&1
  439. mapfile -t options < <(
  440. dialog --separate-output --title "Guix" --checklist "Guix Options" 22 72 3 \
  441. -- --no-offload "--no-offload" off \
  442. --commit "--commit" off \
  443. --allow-downgrades "--allow-downgrades" off \
  444. --fallback "--fallback" off \
  445. --disable-authentication "--disable-authentication" off \
  446. 2>&1 2>&1 1>&3
  447. )
  448. declare -p options
  449. for option in "${options[@]}"
  450. do
  451. if [[ "$option" == "--commit" ]]
  452. then
  453. exec 3>&1
  454. options=("${options[@]/--commit}")
  455. commit=$(dialog --backtitle "Guix commit" --inputbox "Enter Guix's Git commit" 8 60 2>&1 1>&3)
  456. exec 3>&-
  457. fi
  458. if [[ "$option" == "--allow-downgrades" ]]
  459. then
  460. options=("${options[@]/--allow-downgrades}")
  461. allow_downgrades=true
  462. fi
  463. if [[ "$option" == "--fallback" ]]
  464. then
  465. options=("${options[@]/--fallback}")
  466. fallback=true
  467. fi
  468. if [[ "$option" == "--disable-authentication" ]]
  469. then
  470. options=("${options[@]/--disable-authentication}")
  471. disable_authentication=true
  472. fi
  473. done
  474. }
  475. {
  476. exec 3>&1
  477. mapfile -t selection < <(
  478. dialog --separate-output --title "Guix" --checklist "Guix Operations" 22 72 3 \
  479. "pull channels" "Test build and update channel file" "${STATE:-off}" \
  480. pull "Pull new changes" "${STATE:-on}" \
  481. "system build" "Build system" "${STATE:-on}" \
  482. "home build" "Build home" "${STATE:-on}" \
  483. "home switch" "Reconfigure home" "${STATE:-on}" \
  484. "manifest apply" "Apply package manifest" "${STATE:-on}" \
  485. "system switch" "Reconfigure system" "${STATE:-on}" \
  486. "distribute" "Pull on remote hosts" "${STATE:-off}" \
  487. "system deploy" "Deploy to remote hosts" "${STATE:-off}" \
  488. 2>&1 2>&1 1>&3
  489. )
  490. declare -p selection
  491. exec 3>&-
  492. }
  493. clear
  494. (
  495. set -ex
  496. for operation in "${selection[@]}"
  497. do
  498. eval "guix $operation $options"
  499. done
  500. )
  501. ;;
  502. pull)
  503. case "$2" in
  504. channels)
  505. (
  506. set -e
  507. cd "${HOME}/.local/share/chezmoi" || exit 1
  508. make dotfiles/channels-current.scm
  509. if [[ $(git diff dotfiles/channels-current.scm) != "" ]]
  510. then
  511. if git commit -m "channels-current: Update." dotfiles/channels-current.scm
  512. then
  513. :
  514. else
  515. exit 1
  516. fi
  517. fi
  518. )
  519. ;;
  520. *)
  521. guix_command=(
  522. "command"
  523. "guix" "pull"
  524. )
  525. if [[ -n $channels_file ]]
  526. then
  527. guix_command+=(
  528. "--channels=${channels_file}"
  529. )
  530. else
  531. guix_command+=(
  532. "--channels=${HOME}/.local/share/chezmoi/dotfiles/channels-current.scm"
  533. )
  534. fi
  535. if [[ -n $dry_run ]]
  536. then
  537. guix_command=(
  538. echo
  539. "${guix_command[@]}"
  540. )
  541. fi
  542. if [[ -n $commit ]]
  543. then
  544. guix_command+=("--commit=$commit")
  545. fi
  546. if [[ -n $allow_downgrades ]]
  547. then
  548. guix_command+=("--allow-downgrades")
  549. fi
  550. if [[ -n $fallback ]]
  551. then
  552. guix_command+=("--fallback")
  553. fi
  554. if [[ -n $disable_authentication ]]
  555. then
  556. guix_command+=("--disable-authentication")
  557. fi
  558. (set -ex; "${guix_command[@]}" "${@:2}"; sudo --login "${guix_command[@]}" "${@:2}")
  559. esac
  560. ;;
  561. distribute)
  562. "$(guix build --file="$HOME/.local/share/chezmoi/dotfiles/ansible/guix.scm" "${@:2}")"
  563. ;;
  564. prebuild)
  565. guix_command=(
  566. echo
  567. sudo --login
  568. GUIX_PACKAGE_PATH="$guix_modules"
  569. "${HOME}/src/git.savannah.gnu.org/git/guix/pre-inst-env"
  570. guix
  571. system
  572. build
  573. --fallback
  574. --no-grafts
  575. )
  576. for module in "${guix_extra_modules[@]}"
  577. do
  578. guix_command+=("--load-path=${module}")
  579. done
  580. guix_command+=(
  581. "$HOME/.local/share/chezmoi/dotfiles/guixsd/guixsd.scm"
  582. )
  583. sudo --login "${guix_command[@]}" "${@:2}"
  584. ;;
  585. prereconfigure)
  586. guix_command=(
  587. "${HOME}/src/git.savannah.gnu.org/git/guix/pre-inst-env"
  588. "guix"
  589. )
  590. for module in "${guix_extra_modules[@]}"
  591. do
  592. guix_command+=("--load-path=${module}")
  593. done
  594. guix_command+=(
  595. system reconfigure
  596. --load-path="$guix_modules"
  597. --fallback "$HOME/.local/share/chezmoi/dotfiles/guixsd/guixsd.scm"
  598. --no-grafts
  599. "$HOME/.local/share/chezmoi/dotfiles/guixsd/guixsd.scm"
  600. )
  601. sudo --login "${guix_command[@]}" "${@:2}"
  602. ;;
  603. # repl)
  604. # GUILE_AUTO_COMPILE=0 command guix repl -L "$guix_modules" "${@:3}"
  605. # ;;
  606. remote)
  607. case "$2" in
  608. reboot)
  609. ansible-playbook <(
  610. cat <<'EOF'
  611. - hosts: guix_vm
  612. become: true
  613. tasks:
  614. - reboot: search_paths=/home/oleg/bin
  615. EOF
  616. )
  617. ;;
  618. esac
  619. ;;
  620. system)
  621. case "$2" in
  622. build)
  623. sudo --login GUILE_LOAD_PATH="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}" command guix system build \
  624. -L "$guix_modules" \
  625. "${@:3}" \
  626. "$HOME/.local/share/chezmoi/dotfiles/guixsd/$HOSTNAME.scm"
  627. ;;
  628. deploy)
  629. (
  630. set -ex
  631. guix deploy -L "$guix_modules" "${@:3}" \
  632. "$HOME/.local/share/chezmoi/dotfiles/guixsd/deploy.scm"
  633. )
  634. ;;
  635. reconfigure)
  636. sudo --login GUILE_LOAD_PATH="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}" command guix system reconfigure \
  637. -L "$guix_modules" \
  638. --no-bootloader "${@:3}" \
  639. "$HOME/.local/share/chezmoi/dotfiles/guixsd/$HOSTNAME.scm"
  640. ;;
  641. switch)
  642. guix_command=(
  643. sudo --login GUILE_LOAD_PATH="${HOME}/.local/share/chezmoi/dotfiles/guixsd/modules:${GUILE_LOAD_PATH}" command guix system reconfigure \
  644. -L "$guix_modules" \
  645. "${@:3}" \
  646. "$HOME/.local/share/chezmoi/dotfiles/guixsd/$HOSTNAME.scm"
  647. )
  648. if [[ -n $allow_downgrades ]]
  649. then
  650. guix_command+=("--allow-downgrades")
  651. fi
  652. "${guix_command[@]}"
  653. if [[ -n $fallback ]]
  654. then
  655. guix_command+=("--fallback")
  656. fi
  657. ;;
  658. *)
  659. command guix system "${@:2}"
  660. ;;
  661. esac
  662. ;;
  663. update)
  664. (
  665. set -e
  666. guix pull
  667. guix system build
  668. guix manifest
  669. guix system switch
  670. set +e
  671. )
  672. ;;
  673. master-staging)
  674. git -C "${HOME}/src/git.savannah.gnu.org/git/guix" shortlog -n upstream/master..upstream/staging
  675. ;;
  676. qemu)
  677. # https://wiki.archlinux.org/index.php/QEMU#Creating_bridge_manually
  678. printf -v macaddr "52:54:%02x:%02x:%02x:%02x" \
  679. $(( RANDOM & 0xff)) $(( RANDOM & 0xff )) $(( RANDOM & 0xff)) $(( RANDOM & 0xff ))
  680. sudo command qemu-system-x86_64 -daemonize -enable-kvm \
  681. -smp cores=4,threads=1 -cpu host -m 4096 -vga virtio -full-screen \
  682. -net nic,model=virtio,macaddr="$macaddr" -net bridge,br=br0 \
  683. "$@"
  684. ;;
  685. clean)
  686. (
  687. set -x
  688. command guix package --delete-generations=1m
  689. command guix pull --delete-generations=1m
  690. command guix gc --list-failures | xargs guix gc --clear-failures
  691. sudo --login command guix system delete-generations 1m
  692. sudo --login command guix pull --delete-generations=1m
  693. )
  694. ;;
  695. profiles)
  696. echo "$(readlink --canonicalize $HOME/.guix-profile)" \
  697. "$(readlink --canonicalize /run/current-system)" \
  698. "$(readlink --canonicalize $HOME/.config/guix/current)"
  699. ;;
  700. test-vm)
  701. eval "$(sed 's,-nic user[^ ]* ,,' "$(./pre-inst-env guix system vm --no-offload "$2")" | tail -1 | sed 's/\sexec\s//') -m 4096 -smp 2 -nic user,model=virtio-net-pci,hostfwd=tcp::10022-:22"
  702. ;;
  703. updatedb)
  704. updatedb \
  705. --localpaths=/gnu/store \
  706. --findoptions='( -path /gnu/store/.links -o -name *.drv -o -name *.chroot ) -prune -o -type f -print' \
  707. --output="$HOME/.config/guix/dbfile"
  708. ;;
  709. locate)
  710. locate -d "$HOME/.config/guix/dbfile" "${@:2}"
  711. ;;
  712. xpanes)
  713. guix_machines=(
  714. vm1.wugi.info
  715. vm2.wugi.info
  716. vm3.wugi.info
  717. vm4.wugi.info
  718. vm5.wugi.info
  719. ws1.wugi.info
  720. localhost
  721. )
  722. xpanes -c 'ssh {}' "${guix_machines[@]}"
  723. ;;
  724. depends)
  725. for package in $(guix package --list-installed | cut --fields=1)
  726. do
  727. if guix graph "$package" | grep --quiet "$2"
  728. then
  729. echo "$package"
  730. fi
  731. done
  732. ;;
  733. *)
  734. command guix "$@"
  735. ;;
  736. esac
  737. }
  738. maintenance()
  739. {
  740. case "$1" in
  741. upgrade)
  742. (
  743. set -xe
  744. cd "${HOME}/.local/share/chezmoi" || exit 1
  745. make dotfiles/nix/flake.lock
  746. if make dotfiles/nix/flake.nix
  747. then
  748. :
  749. else
  750. git restore dotfiles/nix/flake.lock
  751. fi
  752. )
  753. ;;
  754. *)
  755. command nix "$@"
  756. ;;
  757. esac
  758. }
  759. listen_ports()
  760. {
  761. ss -tulpn | awk '{ print $5 }' | cut -d: -f 2 | sort -un | xargs echo
  762. }
  763. alias vnc-server-android="vncserver -AcceptSetDesktopSize=no -geometry 1280x720"
  764. # jenkins_log()
  765. # {
  766. # for project in $(curl -s -k "https://admin:$(pass show majordomo/public/jenkins.intr/admin)@jenkins.intr/api/json?pretty=true" | jq -r '.jobs[] | .name'); do
  767. # for job in $(curl -s -k "https://admin:$(pass show majordomo/public/jenkins.intr/admin)@jenkins.intr/job/$project/api/json" | jq -r '.jobs[] | .url'); do
  768. # echo "@ $job" |
  769. # curl -u "admin:$(pass show majordomo/public/jenkins.intr/admin)" -s -k "$job/job/master/lastBuild/consoleText"
  770. # done
  771. # done
  772. # }
  773. # https://markhneedham.com/blog/2015/11/14/jq-filtering-missing-keys/
  774. alias get-todos='scp work:/home/user/src/jord/doc/todo.org ~/src/todo.org '
  775. # nix-shell -E 'with import <nixpkgs> {}; callPackage ./default.nix {}' -A luaCrypto
  776. # nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}';
  777. # grep '^FAIL ' /tmp/6.txt | cut -d '/' -f 2- | cut -d ']' -f 1 | sed 's@^@ext/@'
  778. nix_untar_docker()
  779. {
  780. # argument example: /nix/store/vqi100nf7x7z82pr4lkagasmzl9zj0zp-docker-image-apache2-php56.tar.gz
  781. tar xv --wildcards '*/layer.tar' -f "$1" \
  782. | tee /tmp/tempstore \
  783. | xargs -n1 -I{} tar xvf {}
  784. }
  785. tmux_renumber_windows()
  786. {
  787. tmux movew -r
  788. }
  789. nix_user_uid()
  790. {
  791. nix-build -E 'with import <nixpkgs> {}; runCommand "foo" {} "id"'
  792. }
  793. nix_info()
  794. {
  795. nix-shell -p nix-info --run "nix-info -m"
  796. }
  797. guix_packages_json()
  798. {
  799. curl https://guix.gnu.org/packages.json
  800. }
  801. git_guix_pre_new_build()
  802. {
  803. number="$1"
  804. git log --oneline \
  805. | head -n "$number" \
  806. | grep Add \
  807. | awk '{ print $NF }' \
  808. | cut -d'.' -f 1 \
  809. | xargs ./pre-inst-env guix build --no-grafts
  810. }
  811. git_guix_pre_new_lint()
  812. {
  813. number="$1"
  814. git log --oneline \
  815. | head -n "$number" \
  816. | grep Add \
  817. | awk '{ print $NF }' \
  818. | cut -d'.' -f 1 \
  819. | xargs ./pre-inst-env guix lint
  820. }
  821. git_guix_pre_update()
  822. {
  823. number="$1"
  824. git log --oneline \
  825. | head -n "$number" \
  826. | grep Update \
  827. | awk '{ print $3 }' \
  828. | cut -d: -f 1 \
  829. | xargs ./pre-inst-env guix build --no-grafts
  830. }
  831. git_guix_home()
  832. {
  833. number="$1"
  834. git show "$number" | grep home | cut -d'"' -f 2
  835. }
  836. # archive_dir()
  837. # {
  838. # for dir in $@; do
  839. # mv -vi "$dir" "$HOME/archive/src/"
  840. # done
  841. # }
  842. terraform_init_with_nix()
  843. {
  844. terraform init -plugin-dir ~/.nix-profile/bin "$@"
  845. }
  846. terraform_init()
  847. {
  848. terraform_init_with_nix -plugin-dir ~/go/src/gitlab.intr/majordomo/terraform-provider-majordomo
  849. }
  850. alias tsw='tmuxifier s web'
  851. alias nn='notmuch new'
  852. alias wtr='curl -H "Accept-Language: ru" wttr.in/Санкт-Петербург'
  853. alias hylang='docker run --rm -it hylang'
  854. nix_build()
  855. {
  856. nix_build="$(which nix-build)"
  857. if [[ "$(readlink -f "$PWD")" =~ "majordomo" ]]
  858. then
  859. cmd="sshpass -Ppassphrase -p$(pass show majordomo/private/gitlab.intr/ssh/id_rsa_gitlab_intr) $nix_build --no-out-link"
  860. if grep --quiet buildLayeredImage default.nix
  861. then
  862. cmd="docker load --input $($cmd)"
  863. fi
  864. else
  865. cmd="$nix_build --no-out-link"
  866. fi
  867. case "$1" in
  868. 20.03)
  869. $cmd "$HOME/src/nixpkgs-master" "${@:2}"
  870. ;;
  871. 19.09)
  872. $cmd "$HOME/src/nixpkgs-master" "${@:2}"
  873. ;;
  874. master)
  875. $cmd "$HOME/src/nixpkgs-master" "${@:2}"
  876. ;;
  877. unstable)
  878. $cmd "$HOME/.nix-defexpr/channels/nixos-unstable" "${@:2}"
  879. ;;
  880. *)
  881. $cmd '<nixpkgs>' "$@"
  882. esac
  883. }
  884. nix_shell_python()
  885. {
  886. PYTHONPATH="" nix-shell -p "python35.withPackages(ps: with ps; [ $* ])"
  887. }
  888. nixos_interactive_test()
  889. {
  890. version="$1"
  891. nix-build build.nix \
  892. --cores 4 \
  893. -A "nixpkgsUnstable.php$version-test.driver" \
  894. --no-out-link --show-trace/bin/nixos-run-vms
  895. }
  896. terraform_refresh()
  897. {
  898. NIX_SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/Majordomo_LLC_Root_CA.crt" \
  899. SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs" \
  900. SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt" \
  901. terraform refresh
  902. }
  903. terraform_plan()
  904. {
  905. NIX_SSL_CERT_FILE="$HOME/src/gitlab.intr/office/ssl-certificates/Majordomo_LLC_Root_CA.crt" \
  906. SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs" \
  907. SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt" \
  908. terraform plan -out=plan "$@"
  909. }
  910. terraform_import()
  911. {
  912. NIX_SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/Majordomo_LLC_Root_CA.crt" \
  913. SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs" \
  914. SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt" \
  915. terraform import "$@"
  916. }
  917. terraform_apply()
  918. {
  919. NIX_SSL_CERT_FILE="$HOME/src/gitlab.intr/office/ssl-certificates/Majordomo_LLC_Root_CA.crt" \
  920. SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs" \
  921. SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt" \
  922. terraform apply "plan"
  923. }
  924. terraform_apply_no_plan()
  925. {
  926. NIX_SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/Majordomo_LLC_Root_CA.crt" \
  927. SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs" \
  928. SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt" \
  929. terraform apply
  930. }
  931. terraform_apply_gitlab()
  932. {
  933. grep resource gitlab/*.tf \
  934. | awk '{ gsub("\"",""); print $2, $3 }' \
  935. | sed 's/\s/./' \
  936. | sed 's/^/-target=/' \
  937. | xargs env NIX_SSL_CERT_FILE="/run/current-system/profile/etc/ssl/certs/Majordomo_LLC_Root_CA.crt" SSL_CERT_DIR="/run/current-system/profile/etc/ssl/certs" SSL_CERT_FILE="/run/current-system/profile/etc/ssl/certs/ca-certificates.crt" terraform apply plan
  938. }
  939. terraform_plan_gitlab()
  940. {
  941. grep resource gitlab/*.tf \
  942. | awk '{ gsub("\"",""); print $2, $3 }' \
  943. | sed 's/\s/./' \
  944. | sed 's/^/-target=/' \
  945. | xargs env NIX_SSL_CERT_FILE="/run/current-system/profile/etc/ssl/certs/Majordomo_LLC_Root_CA.crt" SSL_CERT_DIR="/run/current-system/profile/etc/ssl/certs" SSL_CERT_FILE="/run/current-system/profile/etc/ssl/certs/ca-certificates.crt" terraform plan -out=plan
  946. }
  947. terraformer_import_github()
  948. {
  949. terraformer import majordomo \
  950. --token "$GITHUB_TOKEN" \
  951. --organizations wugi-emacs \
  952. --resources=repositories
  953. }
  954. spb_log()
  955. {
  956. ssh spb -- bzcat "$1"
  957. }
  958. ssh_guix_build_log_file()
  959. {
  960. host="$1"
  961. file="$2"
  962. ssh "$host" -- guix build --log-file "$file" | xargs ssh "$host" -- bzcat
  963. }
  964. herd_reload()
  965. {
  966. herd reload root "$HOME/.config/shepherd/init.scm"
  967. }
  968. herd_kill_services_via_awk()
  969. {
  970. for service in $(awk '/define.*service/ { print $NF }' "$HOME/.config/shepherd/init.scm" | sed 's/-service//'); do
  971. pkill "$service"
  972. done
  973. }
  974. docker_strace()
  975. {
  976. container="$1"
  977. docker top "$container" | tail -n +2 | awk '{ print $2 }' | sed 's/^/-p/' | xargs sudo strace -o "$HOME/$container.strace" -f -s 4096
  978. }
  979. docker_strace_pids()
  980. {
  981. container="$1"
  982. docker top "$container" | tail -n +2 | awk '{ print $2 }' | sed 's/^/-p/';
  983. }
  984. vnc_server_zero()
  985. {
  986. sudo chmod 666 /var/run/slim-vt7.auth
  987. xauth merge /var/run/slim-vt7.auth
  988. while true; do
  989. guix shell tigervnc-server -- x0vncserver -PasswordFile "$HOME/.vnc/passwd" -display :0 -rfbport 5960
  990. sleep 5
  991. done
  992. }
  993. ansible_cmdb_my()
  994. {
  995. # https://itnext.io/create-a-host-inventory-in-a-minute-with-ansible-c7bf251166d9
  996. ansible -m setup --tree out/ all
  997. ansible-cmdb -t html_fancy_split -p local_js=1 out/
  998. }
  999. ansible_playbook_wrapper()
  1000. {
  1001. host="$1"
  1002. ANSIBLE_HOST_KEY_CHECKING="False" ansible-playbook \
  1003. --private-key="$HOME/.ssh/id_rsa" \
  1004. --user=root \
  1005. --inventory="$host", \
  1006. --extra-vars=host="$host" \
  1007. --extra-vars=ansible_python_interpreter=/usr/bin/python3 \
  1008. "${@:2}"
  1009. }
  1010. bash_history_top()
  1011. {
  1012. # https://www.commandlinefu.com/commands/view/604/list-of-commands-you-use-most-often
  1013. history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
  1014. }
  1015. fast_scan()
  1016. {
  1017. parallel -j200% -n1 -a textfile-with-hosts.txt nc -vz {} ::: 22
  1018. }
  1019. alias guix-docker-image-minimal='guix pack -f docker --symlink=/bin=bin bash'
  1020. alias find-yml="find -maxdepth 2 -name '*.yml' | grep -vF '.travis.yml' | grep -vF '.gitlab'"
  1021. alias docker-describe-image='dive'
  1022. alias inxi='inxi --full'
  1023. alias ansible-playbook-ping-all="ansible-playbook <(echo -e '---\n- hosts: all\n tasks:\n - ping:')"
  1024. alias ansible-playbook-cache-all="ansible-playbook <(echo -e '---\n- hosts:\n - all\n gather_facts: True\n')"
  1025. alias clock='while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &'
  1026. alias type-like-movie='echo "You can simulate on-screen typing just like in the movies" | pv -qL 10'
  1027. alias top-by-memory='ps aux | sort -nk +4 | tail'
  1028. alias smtpd='python -m smtpd -n -c DebuggingServer localhost:1025'
  1029. alias biggest='du -s * | sort -n | tail'
  1030. alias colors='for code in {0..255}; do echo -e "\\e[38;05;${code}m $code: Test"; done'
  1031. alias ps-tree='ps awwfux | less -S'
  1032. alias share='script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)'
  1033. alias internet-programs='lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2'
  1034. md()
  1035. {
  1036. mkdir -p "$@" && cd "$@"
  1037. }
  1038. kernel_graph()
  1039. {
  1040. lsmod \
  1041. | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' \
  1042. | dot -Tpng \
  1043. | feh -
  1044. }
  1045. netstat_graph()
  1046. {
  1047. netstat -an \
  1048. | grep ESTABLISHED \
  1049. | awk '{print $5}' \
  1050. | awk -F: '{print $1}' \
  1051. | sort \
  1052. | uniq -c \
  1053. | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }' \
  1054. | sort -k2 -n
  1055. }
  1056. random_password()
  1057. {
  1058. length="$1"
  1059. strings /dev/urandom | grep -o '[[:alnum:]]' | head -n "$length" | tr -d '\n'
  1060. }
  1061. # watch -n 1 mysqladmin --user=<user> --password=<password> processlist
  1062. alias alexa-top="curl -qsSl http://s3.amazonaws.com/alexa-static/top-1m.csv.zip 2>/dev/null | zcat | grep .de | head -1000 | awk -F, '{print }'"
  1063. dnsperf_my()
  1064. {
  1065. # https://muff.kiev.ua/content/dnsperf-testirovanie-proizvoditelnosti-dns-servera
  1066. sudo dnsperf -d ~/Downloads/dnsperf-example.txt -s 127.0.0.1 -l 60
  1067. }
  1068. tmuxifier_webs_user()
  1069. {
  1070. account="$(ihs web unix "$1")"
  1071. TMUXIFIER_USER="$(echo "$account" | recsel -P name)" \
  1072. TMUXIFIER_HOST="$(echo "$account" | recsel -P server_name)"s \
  1073. tmuxifier s ssh
  1074. }
  1075. tmuxifier_connect_host()
  1076. {
  1077. host="$1"
  1078. TMUXIFIER_USER=root TMUXIFIER_HOST="$host" tmuxifier w ssh-sudo
  1079. }
  1080. git_clean_up()
  1081. {
  1082. for dir in apache2-php52 apache2-php53 apache2-php54 apache2-php55 apache2-php56 apache2-php70 apache2-php71 apache2-php72 apache2-php73 ; do
  1083. cd $dir
  1084. for branch in $(git branch -r | grep -v master | sed 's|origin/||'); do
  1085. git push origin --delete "$branch"
  1086. done
  1087. cd -
  1088. done
  1089. }
  1090. tmux_ls()
  1091. {
  1092. command tmux ls | cut -d ':' -f 1 2>/dev/null
  1093. }
  1094. tmux()
  1095. {
  1096. case "$1" in
  1097. list)
  1098. session="$(tmux-ls | fzf)"
  1099. if [ "$session" == "" ]
  1100. then
  1101. return 1
  1102. else
  1103. command tmux at -t "$session"
  1104. fi
  1105. ;;
  1106. *)
  1107. command tmux "$@"
  1108. ;;
  1109. esac
  1110. }
  1111. docker_xorg()
  1112. {
  1113. xhost +local:
  1114. # MAYBE:
  1115. # --device /dev/video0 \
  1116. docker run -it \
  1117. -v /tmp/.X11-unix:/tmp/.X11-unix \
  1118. -e DISPLAY \
  1119. --device /dev/dri \
  1120. --device /dev/snd \
  1121. -v /etc/localtime:/etc/localtime:ro \
  1122. --device /dev/input \
  1123. "$@"
  1124. }
  1125. obs_docker_setup()
  1126. {
  1127. # https://github.com/mviereck/x11docker/wiki/Container-sound:-ALSA-or-Pulseaudio
  1128. "$(guix build pulseaudio)/bin/pactl" load-module module-native-protocol-unix socket=/tmp/pulseaudio.socket
  1129. cat > /tmp/pulseaudio.client.conf << EOF
  1130. default-server = unix:/tmp/pulseaudio.socket
  1131. # Prevent a server running in the container
  1132. autospawn = no
  1133. daemon-binary = /bin/true
  1134. # Prevent the use of shared memory
  1135. enable-shm = false
  1136. EOF
  1137. }
  1138. obs_docker()
  1139. {
  1140. docker-xorg \
  1141. --name obs \
  1142. --rm \
  1143. --env PULSE_SERVER=unix:/tmp/pulseaudio.socket \
  1144. --env PULSE_COOKIE=/tmp/pulseaudio.cookie \
  1145. --volume /tmp/pulseaudio.socket:/tmp/pulseaudio.socket \
  1146. --volume /tmp/pulseaudio.client.conf:/etc/pulse/client.conf \
  1147. --volume /home/oleg/obs:/home/obs \
  1148. --volume /home/oleg/.Xauthority:/home/oleg/.Xauthority \
  1149. --volume /srv/music/mp3:/home/obs/music \
  1150. obs
  1151. }
  1152. pacmd()
  1153. {
  1154. case "$1" in
  1155. ladspa)
  1156. command pacmd load-module module-ladspa-sink sink_name=compressor-stereo plugin=sc4_1882 label=sc4 control=1,1.5,401,-30,20,5,12
  1157. ;;
  1158. *)
  1159. command pacmd "$@"
  1160. ;;
  1161. esac
  1162. }
  1163. projectile_ls()
  1164. {
  1165. bash -c 'echo ${0:1:-1}' \
  1166. "$(printf "%b" "$(emacsclient -e "(mapconcat 'identity (mapcar #'expand-file-name (projectile-load-known-projects)) \"\n\")")")" \
  1167. | tr ' ' '\n'
  1168. }
  1169. projectile_command()
  1170. {
  1171. "$@" "$(projectile-ls | fzf)"
  1172. }
  1173. alias projectile-cd="projectile-command cd"
  1174. alias projectile-magit="projectile-command magit"
  1175. microseconds_to_seconds()
  1176. {
  1177. seconds="$1"
  1178. microseconds=$(echo "scale=2;${seconds}/1000000" | bc)
  1179. echo "$microseconds"
  1180. }
  1181. test_openvpn()
  1182. {
  1183. server="$1"
  1184. # https://serverfault.com/questions/262474/how-to-check-that-an-openvpn-server-is-listening-on-a-remote-port-without-using
  1185. echo -e "\x38\x01\x00\x00\x00\x00\x00\x00\x00" |
  1186. timeout 10 nc -u "$server" 1194 | cat -v
  1187. # Output example: @$M-^HM--LdM-t|M-^X^@^@^@^@^@@$M-^HM--LdM-t|M-^X^@^@^@^@^@@$M-^HM--LdM-t|M-^X...
  1188. }
  1189. # jq like for http
  1190. alias hq='pup'
  1191. guix_graph_chromium()
  1192. {
  1193. package="$1"
  1194. GUILE_LOAD_PATH=/home/oleg/src/git.savannah.gnu.org/git/guix:GUILE_LOAD_PATH guix graph -b d3js \
  1195. "$package" > /tmp/out.html && chromium --app=file:///tmp/out.html
  1196. }
  1197. docker_run_ansible()
  1198. {
  1199. docker run \
  1200. --network=host \
  1201. -v /home/oleg/src/dotfiles:/root/src/dotfiles \
  1202. -v /root/.ssh:/root/.ssh \
  1203. -v /home/oleg/.ansible-hosts:/etc/ansible/hosts \
  1204. -v /home/oleg/telnet.yml:/telnet.yml \
  1205. -v /home/oleg/ansible-out/ansible.cfg:/etc/ansible/ansible.cfg \
  1206. --rm -it quay.io/ansible/molecule:2.22 sh
  1207. }
  1208. alias bash-pure='env -i "$(command -v bash)" --login --noprofile --norc'
  1209. alias root-shedule="sudo herd schedule mcron 10"
  1210. alias tmux-reload="tmux source-file ~/.tmux.conf"
  1211. less_color()
  1212. {
  1213. LESSOPEN="| ~/.guix-profile/bin/src-hilite-lesspipe.sh %s"
  1214. export LESSOPEN
  1215. LESS=' -R '
  1216. export LESS
  1217. }
  1218. container()
  1219. {
  1220. case "$1" in
  1221. lint)
  1222. docker run --rm --interactive hadolint/hadolint:v1.17.2-8-g65736cb-debian < Dockerfile
  1223. ;;
  1224. ip)
  1225. docker ps --format='{{.ID}}' \
  1226. | xargs docker inspect \
  1227. | jq -r '.[] | [.NetworkSettings.Networks.bridge.IPAddress, .Config.Image] | @tsv'
  1228. ;;
  1229. intr-list)
  1230. mjru-docker-list-intr
  1231. ;;
  1232. intr-pull)
  1233. group="$1" # For example: “mail”.
  1234. for repo in $docker_list_intr; do
  1235. docker pull "docker-registry.intr/$repo"
  1236. done
  1237. ;;
  1238. intr-ps)
  1239. ANSIBLE_NOCOLOR=1 ansible swarm -m shell -a 'docker ps --no-trunc' --become --ask-become-pass
  1240. ;;
  1241. *)
  1242. docker "$@"
  1243. ;;
  1244. esac
  1245. }
  1246. if [ -f /run/current-system/profile/etc/bash_completion.d/docker ]; then
  1247. source /run/current-system/profile/etc/bash_completion.d/docker
  1248. complete -F _docker container
  1249. fi
  1250. ip_to_decimal()
  1251. {
  1252. ip="$1" # e.g. 127.0.0.1
  1253. perl -le "print unpack(\"N\", $ip)"
  1254. }
  1255. alias random-pass="perl -le 'print map { (a..z)[rand 26] } 1..8'"
  1256. urlescape ()
  1257. {
  1258. perl -MURI::Escape -lne 'print uri_escape($_)' <<< "$1"
  1259. }
  1260. urlunescape ()
  1261. {
  1262. perl -MURI::Escape -lne 'print uri_unescape($_)' <<< "$1"
  1263. }
  1264. build_farm()
  1265. {
  1266. emacsclient -e "(wi-build-farm \"$1\")"
  1267. }
  1268. find_touch_go()
  1269. {
  1270. find . -name '*.go' -exec touch {} +
  1271. }
  1272. function password()
  1273. {
  1274. if [ "$#" -ne 2 ]
  1275. then
  1276. (
  1277. cd "$HOME/.password-store" || exit
  1278. pass show "$(find . -not -path './.gitattributes' -not -path './.git/*' -type f | sed 's@\./@@' | sed 's@\.gpg@@' | fzf)" \
  1279. | xclip -i -sel p -f | xclip -i -sel c
  1280. )
  1281. else
  1282. pass "$@"
  1283. fi
  1284. }
  1285. if [ -f "$HOME/.guix-profile/etc/bash_completion.d/pass" ]; then
  1286. source "$HOME/.guix-profile/etc/bash_completion.d/pass"
  1287. complete -o filenames -F _pass password
  1288. fi
  1289. alias password='EDITOR=nano password'
  1290. genpass()
  1291. {
  1292. tr -dc 'a-zA-Z0-9_#@.-' < /dev/urandom | head -c "${1:-14}"
  1293. }
  1294. pass_list_all()
  1295. {
  1296. (
  1297. cd ~/.password-store || exit
  1298. for password in $(find . -not -path './.gitattributes' -not -path './.git/*' -type f | sed 's@\./@@' | sed 's@\.gpg@@'); do
  1299. pass show "$password" | tr -d '\n'
  1300. echo
  1301. done
  1302. )
  1303. }
  1304. gmail_mail()
  1305. {
  1306. # Source: https://www.commandlinefu.com/commands/view/3380/check-your-unread-gmail-from-the-command-line
  1307. curl -u "go.wigust:$(pass show myaccount.google.com/apppasswords/go.wigust)" \
  1308. --silent "https://mail.google.com/mail/feed/atom" \
  1309. | tr -d '\n' \
  1310. | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' \
  1311. | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
  1312. # Alternative variant:
  1313. # Checks your unread Gmail from the command line
  1314. # curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;
  1315. }
  1316. gmail_send()
  1317. {
  1318. rcpt="$1"
  1319. # Send email with curl and gmail
  1320. curl -n --ssl-reqd --mail-from "<go.wigust@gmail.com>" --mail-rcpt "$rcpt" --url smtps://smtp.gmail.com:465 -T file.txt
  1321. }
  1322. cmdfu()
  1323. {
  1324. curl -L "http://www.commandlinefu.com/commands/matching/$*/$(echo -n "$@" | openssl base64)/plaintext";
  1325. }
  1326. clfavs()
  1327. {
  1328. # backup all your commandlinefu.com favourites to a plaintext file
  1329. URL="http://www.commandlinefu.com"
  1330. wget -O - --save-cookies c --post-data "username=$1&password=$2&submit=Let+me+in" $URL/users/signin
  1331. for i in $(seq 0 25 "$3"); do
  1332. wget -O - --load-cookies c "$URL/commands/favourites/plaintext/$i" >> "$4"
  1333. done
  1334. rm -f c
  1335. }
  1336. gnuplot_bash_history()
  1337. {
  1338. HISTTIMEFORMAT='' history \
  1339. | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' \
  1340. | sort -rn \
  1341. | head > /tmp/cmds ; gnuplot -persist <<<'plot "/tmp/cmds" using 1:xticlabels(2) with boxes'
  1342. }
  1343. kill_xterm_on_display()
  1344. {
  1345. display="$1"
  1346. for pid in $(pidof xterm); do
  1347. if [[ $1 = $(tr '\000' '\n' < "/proc/$pid/environ" | grep "$display" | cut -d= -f 2) ]]; then
  1348. kill "$pid"
  1349. fi
  1350. done
  1351. }
  1352. docker_top_strace()
  1353. {
  1354. container="$1"
  1355. docker top "$container" \
  1356. | awk '{ print $2 }' \
  1357. | tail -n +2 \
  1358. | sed 's/^/-p/' \
  1359. | xargs strace -s 10000 -f -o /tmp/docker.strace
  1360. }
  1361. active_hms()
  1362. {
  1363. curl -s --user jenkins:"$(pass show majordomo/private/jenkins/jenkins)" nginx{1,2}-mr:8080/hms | jq -r .active | uniq
  1364. }
  1365. jenkins_build_project_branch()
  1366. {
  1367. dir="$1"
  1368. project="$2"
  1369. branch="$3"
  1370. url="$JENKINS_URL/job/$dir/job/$project/job/$branch"
  1371. curl -X POST \
  1372. -u "admin:$(pass show jenkins/admin-api-key)" \
  1373. "$url/build"
  1374. echo "$url/lastBuild/console"
  1375. }
  1376. # Create a new directory and enter it
  1377. mkd()
  1378. {
  1379. mkdir -p "$@"
  1380. cd "$@" || exit
  1381. }
  1382. # Make a temporary directory and enter it
  1383. tmpd()
  1384. {
  1385. local dir
  1386. if [ $# -eq 0 ]; then
  1387. dir=$(mktemp -d)
  1388. else
  1389. dir=$(mktemp -d -t "${1}.XXXXXXXXXX")
  1390. fi
  1391. cd "$dir" || exit
  1392. }
  1393. # Run `dig` and display the most useful info
  1394. digga()
  1395. {
  1396. dig +nocmd "$1" any +multiline +noall +answer
  1397. }
  1398. alias feh-bg="feh --borderless --image-bg black --auto-zoom --draw-filename"
  1399. lsp_mode()
  1400. {
  1401. docker run --tty --interactive --rm \
  1402. --volume "$PWD:/mnt/workspace" \
  1403. --volume /etc/localtime:/etc/localtime:ro \
  1404. --volume "$HOME/.gnupg:${HOME}/.gnupg" \
  1405. --volume /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket \
  1406. --volume /tmp/.X11-unix:/tmp/.X11-unix \
  1407. --volume /etc/machine-id:/etc/machine-id:ro \
  1408. --volume /home/oleg/src/gitlab.intr/hms:/src \
  1409. --volume "$PWD/emacs.d/:/home/lsp/.emacs.d" \
  1410. --user 1000:1000 \
  1411. --env DISPLAY="$DISPLAY" \
  1412. --network=host \
  1413. "${1:-yyoncho/lsp-emacs-docker}" emacs
  1414. }
  1415. git_all_history()
  1416. {
  1417. git log --oneline | awk '{ print $1 }' | xargs git show
  1418. }
  1419. git_grep_removed()
  1420. {
  1421. git log --full-diff -G '\*\*REMOVED\*\*'
  1422. }
  1423. git_prune()
  1424. {
  1425. git reflog expire --expire=now --all && git gc --prune=now --aggressive
  1426. }
  1427. bfg()
  1428. {
  1429. case "$1" in
  1430. pass)
  1431. command bfg --replace-text <(git-pass-secrets)
  1432. ;;
  1433. esac
  1434. }
  1435. atoi()
  1436. {
  1437. #Returns the integer representation of an IP arg, passed in ascii dotted-decimal notation (x.x.x.x)
  1438. IP=$1; IPNUM=0
  1439. for (( i=0 ; i<4 ; ++i )); do
  1440. ((IPNUM+=${IP%%.*}*$((256**$((3-i))))))
  1441. IP=${IP#*.}
  1442. done
  1443. echo $IPNUM
  1444. }
  1445. itoa()
  1446. {
  1447. #returns the dotted-decimal ascii form of an IP arg passed in integer format
  1448. echo -n $(($(($(($((${1}/256))/256))/256))%256)).
  1449. echo -n $(($(($((${1}/256))/256))%256)).
  1450. echo -n $(($((${1}/256))%256)).
  1451. echo $((${1}%256))
  1452. }
  1453. pactl_ladspa()
  1454. {
  1455. # TODO: LADSPA_PATH=/gnu/store/…-swh-plugins/lib/ladspa
  1456. # https://github.com/gotbletu/shownotes/blob/master/pulseaudio-dynamic-range-compression.md
  1457. pactl load-module module-ladspa-sink master=0 sink_name=compressor-stereo plugin=sc4_1882 label=sc4 control=1,1.5,401,-30,20,5,12
  1458. pactl load-module module-ladspa-sink master=1 sink_name=compressor-stereo plugin=sc4_1882 label=sc4 control=1,1.5,401,-30,20,5,12
  1459. }
  1460. docker_openresty()
  1461. {
  1462. docker run \
  1463. --entrypoint '' \
  1464. --interactive \
  1465. --name openresty \
  1466. --network=host \
  1467. --tty \
  1468. openresty/openresty:bionic bash
  1469. }
  1470. nix_python_with_pkgs()
  1471. {
  1472. nix-shell -p python "python.withPackages (python-packages: with python-packages; [ $* ])"
  1473. }
  1474. bpython()
  1475. {
  1476. nix-shell -p python3 "python3.withPackages (python-packages: with python-packages; [ bpython ])" --run bpython
  1477. }
  1478. http_prompt()
  1479. {
  1480. nix-shell -I "$HOME/.nix-defexpr/channels/nixos-unstable" \
  1481. -p http-prompt \
  1482. --run "http-prompt $@"
  1483. }
  1484. nix_python2_with_pkgs()
  1485. {
  1486. nix-shell -p python2 "python2.withPackages (python-packages: with python-packages; [ $* ])"
  1487. }
  1488. firefox()
  1489. {
  1490. case "$1" in
  1491. kill)
  1492. pgrep -fa firefox-wrapped | grep -v 'test' | cut -d ' ' -f 1 | xargs kill
  1493. ;;
  1494. sync)
  1495. rsync --archive --progress "$HOME/.mozilla/firefox/j56dvo43.default-1520714705340" vm1.wugi.info:.mozilla/firefox/
  1496. ;;
  1497. *)
  1498. command firefox "$@"
  1499. esac
  1500. }
  1501. firefox_esr_debian()
  1502. {
  1503. xhost +local:
  1504. docker run \
  1505. --tty \
  1506. --interactive \
  1507. --rm \
  1508. --name \
  1509. firefox-java \
  1510. --env \
  1511. DISPLAY="$DISPLAY" \
  1512. --volume \
  1513. /tmp/.X11-unix:/tmp/.X11-unix \
  1514. cmaohuang/firefox-java \
  1515. /usr/bin/firefox \
  1516. --new-instance
  1517. }
  1518. mitmproxy()
  1519. {
  1520. PYTHONPATH='' command mitmproxy --set ssl_insecure=true "$@"
  1521. }
  1522. alias ssh-clean='find ~/.ssh -type s -delete'
  1523. alias pass='EDITOR=nano pass'
  1524. alias ansible-vault='EDITOR=nano ansible-vault'
  1525. alias sw1-dh507='connect sw1-dh507'
  1526. alias sw1-mr11="connect sw1-mr11"
  1527. alias nix='EDITOR=less VISUAL="emacsclient -cn" nix'
  1528. alias dotfiles='EDITOR=nano dotfiles'
  1529. if [ -f "$HOME/.nix-profile/share/bash-completion/completions/chezmoi.bash" ]; then
  1530. source "$HOME/.nix-profile/share/bash-completion/completions/chezmoi.bash"
  1531. complete -o default -F __start_chezmoi dotfiles
  1532. fi
  1533. if [ -f "$HOME/.guix-profile/etc/bash_completion.d/restic" ]; then
  1534. source "$HOME/.guix-profile/etc/bash_completion.d/restic"
  1535. complete -o default -F __start_restic backup
  1536. fi
  1537. mycut()
  1538. {
  1539. command cut --characters="-$(tput cols)" "$@"
  1540. }
  1541. src_clean()
  1542. {
  1543. for directory in src archive/src; do
  1544. command src-clean --directory=$directory --author=go.wigust@gmail.com --ignore=src/dotfiles,src/rofi-themes,src/rfc,src/guix-videos,src/guile,src/fdroiddata,src/emacs-tramp-auto-auth,src/docker-nextcloud,archive/src/sendnotify,archive/src/php,archive/src/my-guix,archive/src/malware-scanner,archive/src/linux-panic,archive/src/linux,archive/src/guile-shepherd,archive/src/groovy,archive/src/gentoo,archive/src/freebsd,archive/src/cpython,archive/src/bash,archive/src/arch-packages,archive/src/arch-community
  1545. done
  1546. }
  1547. transmission_remote()
  1548. {
  1549. case "$1" in
  1550. clean)
  1551. command transmission-remote --list | awk '$2 == "100%" { system("transmission-remote --torrent " $1 " --remove") }'
  1552. ;;
  1553. *)
  1554. command transmission-remote "$@"
  1555. ;;
  1556. esac
  1557. }
  1558. rg()
  1559. {
  1560. case "$1" in
  1561. dist)
  1562. command rg "${@:2}" "$HOME"/{src/nixpkgs-master,src/guix,archive/src/{gentoo,freebsd,openbsd-ports,arch-{community,packages}}}
  1563. ;;
  1564. *)
  1565. command rg --no-heading "$@"
  1566. ;;
  1567. esac
  1568. }
  1569. if [ -f "$HOME/.bash.d/slack.bash" ]
  1570. then
  1571. # shellcheck source=.bash.d/mjru.bash
  1572. source "$HOME/.bash.d/slack.bash"
  1573. fi
  1574. if [ -f "$HOME/.bash.d/mjru.bash" ]
  1575. then
  1576. # shellcheck source=.bash.d/mjru.bash
  1577. source "$HOME/.bash.d/mjru.bash"
  1578. fi
  1579. chezmoi()
  1580. {
  1581. case "$1" in
  1582. add-all)
  1583. for file in $(command chezmoi diff | awk '/a\/home/ { print $NF }' | sed 's/^a//'); do
  1584. command chezmoi add "$file"
  1585. done
  1586. ;;
  1587. *)
  1588. command chezmoi "$@"
  1589. ;;
  1590. esac
  1591. }
  1592. if [ -f "$HOME/.bash_completion.d/mail" ]
  1593. then
  1594. source "$HOME/.bash_completion.d/mail"
  1595. fi
  1596. if [ -f "$HOME/.bash_completion.d/connect" ]
  1597. then
  1598. source "$HOME/.bash_completion.d/connect"
  1599. fi
  1600. gitlab()
  1601. {
  1602. GITLAB_API_PRIVATE_TOKEN="$(pass show majordomo/private/gitlab.intr/tokens/terraform)"
  1603. GITLAB_API_ENDPOINT="https://gitlab.intr/api/v4"
  1604. GITLAB_API_HTTPARTY_OPTIONS="{verify: false}"
  1605. case "$1" in
  1606. create_project)
  1607. group="$2"
  1608. name="$3"
  1609. command gitlab create_project "$name" "{visibility: public, namespace_id: $group}"
  1610. echo "https://gitlab.intr/$group/$name"
  1611. echo "git@gitlab.wugi.info:$group/$name.git"
  1612. ;;
  1613. *)
  1614. command gitlab "$@"
  1615. esac
  1616. }
  1617. youtube_dl_to_org()
  1618. {
  1619. jq --join-output '.entries[] | "- [ ] [[https://www.youtube.com/watch?v=", .id, "]", "[", .title, "]]\n"' "$@"
  1620. }
  1621. gita()
  1622. {
  1623. case "$1" in
  1624. emacs)
  1625. emacsclient -cn "$(command gita ls "$2")"
  1626. ;;
  1627. cd)
  1628. cd "$(command gita ls "$2")"
  1629. ;;
  1630. --help)
  1631. command gita --help "$@"
  1632. glow https://github.com/nosarthur/gita
  1633. ;;
  1634. week)
  1635. PAGER='' command gita super log --format="%ai %H %s" --date=relative --since="${2:-1} weeks ago" "${@:3}"
  1636. ;;
  1637. *)
  1638. command gita "$@"
  1639. ;;
  1640. esac
  1641. }
  1642. alias godaddy="GODADDY_DOMAIN_NAME=wugi.info godaddy"
  1643. wugi.info()
  1644. {
  1645. case "$1" in
  1646. a)
  1647. godaddy list a
  1648. ;;
  1649. cname)
  1650. godaddy list cname
  1651. ;;
  1652. ns)
  1653. godaddy list ns
  1654. ;;
  1655. esac
  1656. }
  1657. stumpwm_refcard()
  1658. {
  1659. (
  1660. cd "/home/oleg/src/git.savannah.gnu.org/git/guix-maintenance/doc/refcard" || exit 1
  1661. # convert -density 200 -rotate 90 "$(guix build -f build.scm)"/stumpwm-refcard.pdf - | zathura -
  1662. case "$1" in
  1663. wallpaper)
  1664. convert -trim -quality 100 -negate -density 130 -rotate 90 "$(guix build -f build.scm)"/stumpwm-refcard.pdf /tmp/out.png; feh --bg-center /tmp/out.png
  1665. ;;
  1666. *)
  1667. zathura "$(guix build -f build.scm)"/stumpwm-refcard.pdf
  1668. esac
  1669. )
  1670. }
  1671. ci()
  1672. {
  1673. "$BROWSER" "$CI"
  1674. }
  1675. elktail()
  1676. {
  1677. case "$1" in
  1678. --help|-h)
  1679. command elktail --help
  1680. echo "\
  1681. general commands
  1682. nginx show nginx logs
  1683. hms show log messages from hms index
  1684. trace trace OPERATION_IDENTITY in hms index
  1685. "
  1686. ;;
  1687. nginx)
  1688. command elktail -url 'http://es:9200' -i 'nginx-*' -n 10000 -l -f '%remote_addr %hostname %path %method %code %http_host'
  1689. ;;
  1690. hms)
  1691. # log_level:DEBUG
  1692. # log_level:ERROR
  1693. # stack:"$(curl --silent --user "jenkins:$(pass show majordomo/private/jenkins/jenkins)" -X GET http://nginx1.intr:8080/hms | jq --raw-output .active)"
  1694. command elktail \
  1695. -url 'http://es:9200' \
  1696. -i 'hms-*' \
  1697. -n 10000 \
  1698. -l \
  1699. -f '%@timestamp %log_level %stack %sleuth_trace %log_message' \
  1700. -a "$(printf "%s" "$(date --utc '+%FT%H:%M:00.000Z' --date '4 hours ago')")" \
  1701. "${@:3}" \
  1702. | grep --invert-match "ftp-user not found by" \
  1703. | grep --invert-match "org.apache.catalina.connector.RequestFacade" \
  1704. | grep --invert-match "Running the evict task with compensationTime" \
  1705. | grep --invert-match "Resolving eureka endpoints via configuration" \
  1706. | grep --invert-match "quotaUsed: " \
  1707. | grep --invert-match "unixAccounts quotaReport for host"
  1708. ;;
  1709. trace)
  1710. (
  1711. set -x
  1712. command elktail \
  1713. -url 'http://es:9200' \
  1714. -i 'hms-*' \
  1715. -n 10000 \
  1716. -l \
  1717. -f '%@timestamp %log_level %stack %sleuth_trace %log_message' \
  1718. -a "$(printf "%s" "$(date --utc '+%FT%H:%M:00.000Z' --date '5 hours ago')")" \
  1719. sleuth_trace:"$2"
  1720. )
  1721. ;;
  1722. *)
  1723. command elktail "$@"
  1724. ;;
  1725. esac
  1726. }
  1727. brute()
  1728. {
  1729. sudo grep 'Connection closed' /var/log/messages \
  1730. | grep --perl-regexp '(?:[0-9]{1,3}\.){3}[0-9]{1,3}' --only-matching \
  1731. | grep --invert-match 127.0.0.1 \
  1732. | uniq \
  1733. | fzf \
  1734. | xargs sudo ipset add brute
  1735. }
  1736. docker()
  1737. {
  1738. case "$1" in
  1739. deploy)
  1740. command docker rm -f novnc
  1741. command docker rm -f monitoror
  1742. monitoror run
  1743. vnc client novnc
  1744. ;;
  1745. *)
  1746. command docker "$@"
  1747. esac
  1748. }
  1749. lsgpu()
  1750. {
  1751. printf "Memory: %s\n" "$(glxinfo | grep -i -o 'device|memory\|[0-9]\{1,12\} MB' | head -n 1)"
  1752. }
  1753. efi()
  1754. {
  1755. if [ -d /sys/firmware/efi ]
  1756. then
  1757. echo UEFI
  1758. else
  1759. echo BIOS
  1760. fi
  1761. }
  1762. mediatomb()
  1763. {
  1764. case "$1" in
  1765. start)
  1766. command mediatomb -e enp34s0 -f Videos/.mediatomb "${@:2}"
  1767. ;;
  1768. *)
  1769. command mediatomb "$@"
  1770. esac
  1771. }
  1772. if [ -z $IN_NIX_SHELL ]
  1773. then
  1774. if [ -e $HOME/.guix-profile/lib/bash/libguile-bash.so ]
  1775. then
  1776. enable -f "$HOME"/.guix-profile/lib/bash/libguile-bash.so scm
  1777. if [ -e "$HOME"/.bash.d/bash.scm ]
  1778. then
  1779. GUILE_AUTO_COMPILE=0 scm "$HOME"/.bash.d/bash.scm
  1780. fi
  1781. fi
  1782. fi
  1783. if [[ -e $HOME/.guix-profile/bin/chezmoi ]]
  1784. then
  1785. eval "$(chezmoi completion bash)"
  1786. fi
  1787. SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
  1788. export SSH_AUTH_SOCK
  1789. # TODO: Fix imv alias.
  1790. #
  1791. # if [ -n $WAYLAND_DISPLAY ]
  1792. # then
  1793. # alias feh=imv
  1794. # fi
  1795. ssh_sudo()
  1796. {
  1797. sshpass -p"$1" \
  1798. ssh \
  1799. -o UserKnownHostsFile=/dev/null \
  1800. -o StrictHostKeyChecking=no \
  1801. -q \
  1802. -t \
  1803. "$3" \
  1804. -l "$2" \
  1805. -- "set +o history; sudo --stdin --validate --prompt='' <<< \"$1\"; exec -a sudo sudo -i"
  1806. }
  1807. ,s()
  1808. {
  1809. sshpass -p"$1" \
  1810. ssh \
  1811. -o UserKnownHostsFile=/dev/null \
  1812. -o StrictHostKeyChecking=no \
  1813. "${@:2}"
  1814. }
  1815. psql()
  1816. {
  1817. case "$1" in
  1818. *)
  1819. sudo -u postgres psql "$@"
  1820. ;;
  1821. esac
  1822. }
  1823. KUBECTL_WATCH_CGROUP="viddy"
  1824. export KUBECTL_WATCH_CGROUP
  1825. __lazy_kubectl()
  1826. {
  1827. local word_count=${#COMP_WORDS[*]}
  1828. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  1829. case $COMP_CWORD in
  1830. *)
  1831. if [[ $(type -t __start_kubectl) != function ]]
  1832. then
  1833. if [[ -f /home/oleg/.guix-profile/bin/kubectl ]]
  1834. then
  1835. source <(/home/oleg/.guix-profile/bin/kubectl completion bash)
  1836. fi
  1837. fi
  1838. ;;
  1839. esac
  1840. }
  1841. complete -F __lazy_kubectl kubectl
  1842. __lazy_helm()
  1843. {
  1844. local word_count=${#COMP_WORDS[*]}
  1845. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  1846. case $COMP_CWORD in
  1847. *)
  1848. if [[ $(type -t __start_helm) != function ]]
  1849. then
  1850. if [[ -f /home/oleg/.guix-profile/bin/helm ]]
  1851. then
  1852. source <(/home/oleg/.guix-profile/bin/helm completion bash)
  1853. fi
  1854. fi
  1855. ;;
  1856. esac
  1857. }
  1858. complete -F __lazy_helm helm
  1859. kubectl()
  1860. {
  1861. case "$1" in
  1862. master)
  1863. command kubectl get node --output=json \
  1864. | jq --raw-output '.items[] | select(.metadata.labels["node-role.kubernetes.io/master"] == "true") | .metadata.name'
  1865. ;;
  1866. cluster*)
  1867. KUBECONFIG="/home/oleg/.kube/config-mjru-${1}" \
  1868. kubectl \
  1869. exec \
  1870. --stdin=true \
  1871. --tty=true \
  1872. --namespace=kubernetes-tmuxifier \
  1873. tmuxifier-0 \
  1874. -- tmux at
  1875. ;;
  1876. drain)
  1877. if [[ -z "$2" ]]
  1878. then
  1879. cat <<'EOF'
  1880. drain example:
  1881. kubectl drain --ignore-daemonsets --delete-emptydir-data NODE
  1882. kubectl delete pods --all-namespaces --field-selector 'spec.nodeName=NODE,metadata.namespace!=default'
  1883. EOF
  1884. else
  1885. command kubectl drain "${@:2}"
  1886. fi
  1887. ;;
  1888. taint)
  1889. if [[ -z "$2" ]]
  1890. then
  1891. cat <<'EOF'
  1892. drain example:
  1893. kubectl taint node unschedulable=true:NoSchedule kube3
  1894. kubectl taint node unschedulable- kube3
  1895. EOF
  1896. else
  1897. command kubectl drain "${@:2}"
  1898. fi
  1899. ;;
  1900. noschedule)
  1901. case "$2" in
  1902. list)
  1903. command kubectl get nodes -o go-template='{{range $item := .items}}{{with $nodename := $item.metadata.name}}{{range $taint := $item.spec.taints}}{{if and (eq $taint.effect "NoSchedule")}}{{printf "%s\n" $nodename}}{{end}}{{end}}{{end}}{{end}}' \
  1904. | sort --version-sort
  1905. ;;
  1906. esac
  1907. ;;
  1908. prometheus)
  1909. command kubectl -n monitoring get secret prometheus-kube-prometheus-stack-prometheus -o json \
  1910. | jq -r '.data["prometheus.yaml.gz"]' \
  1911. | base64 -d \
  1912. | gunzip
  1913. ;;
  1914. reboot)
  1915. (
  1916. set -ex
  1917. kubectl drain "$2" --ignore-daemonsets --delete-emptydir-data
  1918. ansible "${2}.intr" -m reboot -a 'search_paths=/run/current-system/sw/bin'
  1919. kubectl uncordon "$2"
  1920. )
  1921. ;;
  1922. cilium)
  1923. command kubectl --namespace kube-system get pods --selector=k8s-app=cilium
  1924. ;;
  1925. tmuxifier)
  1926. case "$2" in
  1927. --help)
  1928. echo TMUXIFIER_KUBERNETES_NAMESPACE=cert-manager kubectl tmuxifier mjru-cluster2
  1929. ;;
  1930. mjru-cluster1-view)
  1931. flake="git+https://gitlab.intr/nixos/kubernetes#kubeconfig-view"
  1932. nix build --no-link "$flake"
  1933. TMUXIFIER_TMUX_OPTS="-L kubernetes-cluster1-view" \
  1934. KUBECONFIG="$(nix path-info "$flake")/.kube/config" \
  1935. tmuxifier s kubernetes
  1936. ;;
  1937. mjru-cluster1)
  1938. TMUXIFIER_TMUX_OPTS="-L kubernetes-cluster1" \
  1939. KUBECONFIG="${HOME}/.kube/config-mjru-cluster1" \
  1940. tmuxifier s kubernetes
  1941. ;;
  1942. mjru-cluster2)
  1943. TMUXIFIER_TMUX_OPTS="-L kubernetes-cluster2" \
  1944. KUBECONFIG="${HOME}/.kube/config-mjru-cluster2" \
  1945. tmuxifier s kubernetes
  1946. ;;
  1947. host1)
  1948. TMUXIFIER_TMUX_OPTS="-L config-host1-k3s" \
  1949. KUBECONFIG="${HOME}/.kube/config-host1-k3s" \
  1950. tmuxifier s kubernetes
  1951. ;;
  1952. home)
  1953. TMUXIFIER_TMUX_OPTS="-L kubernetes-home-k8s" \
  1954. KUBECONFIG="${HOME}/.kube/config-home-k8s" \
  1955. tmuxifier s kubernetes
  1956. ;;
  1957. *)
  1958. tmuxifier s kubernetes
  1959. ;;
  1960. esac
  1961. ;;
  1962. *)
  1963. command kubectl "$@"
  1964. ;;
  1965. esac
  1966. }
  1967. __lazy_virtctl()
  1968. {
  1969. local word_count=${#COMP_WORDS[*]}
  1970. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  1971. case $COMP_CWORD in
  1972. *)
  1973. if [[ $(type -t __start_virtctl) != function ]]
  1974. then
  1975. if [[ -f /run/current-system/profile/bin/virtctl ]]
  1976. then
  1977. source <(/run/current-system/profile/bin/virtctl completion bash)
  1978. fi
  1979. fi
  1980. ;;
  1981. esac
  1982. }
  1983. __lazy_glab()
  1984. {
  1985. local word_count=${#COMP_WORDS[*]}
  1986. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  1987. case $COMP_CWORD in
  1988. *)
  1989. if [[ $(type -t __start_glab) != function ]]
  1990. then
  1991. if [[ -f "${HOME}/.nix-profile/bin/glab" ]]
  1992. then
  1993. source <("${HOME}/.nix-profile/bin/glab" completion)
  1994. fi
  1995. fi
  1996. ;;
  1997. esac
  1998. }
  1999. complete -F __lazy_glab glab
  2000. glab()
  2001. {
  2002. case "$1" in
  2003. *)
  2004. command glab "${@:1}"
  2005. ;;
  2006. esac
  2007. }
  2008. __lazy_ipmi()
  2009. {
  2010. local word_count=${#COMP_WORDS[*]}
  2011. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  2012. case $COMP_CWORD in
  2013. *)
  2014. if [[ $(type -t __start_ipmi) != function ]]
  2015. then
  2016. if [[ -f "$HOME/.nix-profile/share/bash-completion/completions/ipmi" ]]
  2017. then
  2018. source "$HOME/.nix-profile/share/bash-completion/completions/ipmi"
  2019. fi
  2020. fi
  2021. ;;
  2022. esac
  2023. }
  2024. complete -F __lazy_ipmi ipmi
  2025. ipmi()
  2026. {
  2027. case "$1" in
  2028. *)
  2029. IPMI_PASSWORD="$(pass show majordomo/public/ipmi/ADMIN)" command ipmi "${@:1}"
  2030. ;;
  2031. esac
  2032. }
  2033. __lazy_cscli()
  2034. {
  2035. local word_count=${#COMP_WORDS[*]}
  2036. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  2037. case $COMP_CWORD in
  2038. *)
  2039. if [[ $(type -t __start_cscli) != function ]]
  2040. then
  2041. if [[ -f /run/current-system/profile/bin/cscli ]]
  2042. then
  2043. source <(/run/current-system/profile/bin/cscli completion bash)
  2044. fi
  2045. fi
  2046. ;;
  2047. esac
  2048. }
  2049. complete -F __lazy_cscli cscli
  2050. __lazy_flux()
  2051. {
  2052. local word_count=${#COMP_WORDS[*]}
  2053. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  2054. case $COMP_CWORD in
  2055. *)
  2056. if [[ $(type -t __start_flux) != function ]]
  2057. then
  2058. if [[ -f /home/oleg/.guix-profile/bin/flux ]]
  2059. then
  2060. source <(/home/oleg/.guix-profile/bin/flux completion bash)
  2061. fi
  2062. fi
  2063. ;;
  2064. esac
  2065. }
  2066. complete -F __lazy_flux flux
  2067. cscli()
  2068. {
  2069. case "$1" in
  2070. *)
  2071. sudo cscli "${@:1}"
  2072. ;;
  2073. esac
  2074. }
  2075. herd()
  2076. {
  2077. case "$1" in
  2078. start)
  2079. case "$2" in
  2080. fzf)
  2081. service="$(sudo command herd status | awk '/ - / { print $NF }' | fzf)"
  2082. sudo command herd enable "$service"
  2083. sudo command herd start "$service"
  2084. ;;
  2085. *)
  2086. command herd enable "${@:2}"
  2087. command herd start "${@:2}"
  2088. ;;
  2089. esac
  2090. ;;
  2091. restart)
  2092. case "$2" in
  2093. mail)
  2094. for service in $(herd status | awk '/isync/ { print $NF }')
  2095. do
  2096. herd start "$service"
  2097. done
  2098. ;;
  2099. *)
  2100. command herd restart "${@:2}"
  2101. ;;
  2102. esac
  2103. ;;
  2104. *)
  2105. command herd "$@"
  2106. ;;
  2107. esac
  2108. }
  2109. opensearch()
  2110. {
  2111. case "$1" in
  2112. index)
  2113. viddy --differences --interval 10 "bash -c 'curl ${2:-opensearch.home}/_cat/indices?pretty | sort -k 3'"
  2114. ;;
  2115. esac
  2116. }
  2117. curl()
  2118. {
  2119. new_args=()
  2120. for var in "$@"
  2121. do
  2122. if [[ "$var" == *"https://api.majordomo.ru/"* ]] || [[ "$var" == *"https://api.maxhost.ru/"* ]]
  2123. then
  2124. json=true
  2125. new_args+=(
  2126. --header "Authorization: Bearer $(mjru-auth)"
  2127. --header 'Content-Type: application/json'
  2128. "$var"
  2129. )
  2130. elif [[ "$var" == *"https://api.hms.development.corp1.majordomo.ru/"* ]] || [[ "$var" == *"http://api.hms.development.corp1.majordomo.ru/"* ]]
  2131. then
  2132. json=true
  2133. new_args+=(
  2134. --header "Authorization: Bearer $(IHS_ENDPOINT=http://api.hms.development.corp1.majordomo.ru mjru-auth)"
  2135. --header 'Content-Type: application/json'
  2136. "$var"
  2137. )
  2138. elif [[ "$var" == *"https://api-dev.intr/"* ]] || [[ "$var" == *"https://api-dev.maxhost.ru/"* ]]
  2139. then
  2140. json=true
  2141. new_args+=(
  2142. --header "Authorization: Bearer $(IHS_ENDPOINT=https://api-dev.intr mjru-auth)"
  2143. --header 'Content-Type: application/json'
  2144. "$var"
  2145. )
  2146. elif [[ "$var" == *"https://kubernetes.intr"* ]] || [[ "$var" == *"https://kubernetes-cluster2.intr"* ]]
  2147. then
  2148. new_args+=(
  2149. --cacert "${HOME}/src/gitlab.intr/office/ssl-certificates/kubernetes/ca.pem"
  2150. --cert "${HOME}/src/gitlab.intr/office/ssl-certificates/kubernetes/admin.pem"
  2151. --key "${HOME}/src/gitlab.intr/office/ssl-certificates/kubernetes/admin-key.pem"
  2152. "$var"
  2153. )
  2154. elif [[ "$var" == *"https://kubernetes.home:6443"* ]]
  2155. then
  2156. new_args+=(
  2157. --cacert /etc/kubernetes/pki/ca.pem
  2158. --cert /etc/kubernetes/pki/admin.pem
  2159. --key /etc/kubernetes/pki/admin-key.pem
  2160. "$var"
  2161. )
  2162. else
  2163. new_args+=($var)
  2164. fi
  2165. done
  2166. command curl "${new_args[@]}"
  2167. if [[ $json == true ]]
  2168. then
  2169. echo
  2170. fi
  2171. }
  2172. dig()
  2173. {
  2174. for var in "$@"
  2175. do
  2176. case "$var" in
  2177. *majordomo.ru|*.intr|172.16.*|*pwhost.ru|*fast-name.ru|*host-support.ru|*litename.ru|*vipname.su|*hoster24.ru)
  2178. name_servers=(
  2179. ns1-mr.intr
  2180. ns2-mr.intr
  2181. ns1-dh.intr
  2182. ns2-dh.intr
  2183. ns.majordomo.ru
  2184. ns2.majordomo.ru
  2185. ns3.majordomo.ru
  2186. ns4.majordomo.ru
  2187. ns1.corp1.majordomo.ru
  2188. ns2.corp2.majordomo.ru
  2189. ns1.svc1.majordomo.ru
  2190. ns2.svc2.majordomo.ru
  2191. ns1.corp2.majordomo.ru
  2192. ns2.corp2.majordomo.ru
  2193. ns1.svc2.majordomo.ru
  2194. ns2.svc2.majordomo.ru
  2195. 8.8.8.8
  2196. 8.8.4.4
  2197. )
  2198. (
  2199. set -x
  2200. command dig "$@"
  2201. )
  2202. for name_server in "${name_servers[@]}"
  2203. do
  2204. (
  2205. set -x
  2206. command dig "$@" "@${name_server}"
  2207. )
  2208. mapfile -t ip_addresses < <(command dig "$@" "@${name_server}" \
  2209. | jc --dig \
  2210. | jq --raw-output .[].answer[].data)
  2211. (
  2212. for ip_address in "${ip_addresses[@]}"
  2213. do
  2214. (
  2215. set -x
  2216. command dig -x "$ip_address" "@${name_server}"
  2217. )
  2218. done
  2219. ) | sort --version-sort
  2220. done
  2221. ;;
  2222. *)
  2223. command dig "$@"
  2224. ;;
  2225. esac
  2226. done
  2227. }
  2228. scream()
  2229. {
  2230. case "$1" in
  2231. *)
  2232. cat <<'EOF'
  2233. scream -i br154.154 -u -p 16400
  2234. EOF
  2235. command scream "$@"
  2236. ;;
  2237. esac
  2238. }
  2239. kresd()
  2240. {
  2241. case "$1" in
  2242. clear)
  2243. sudo socat - "UNIX-CONNECT:/var/cache/knot-resolver/control/$(pidof kresd)" <<< 'cache.clear()'
  2244. ;;
  2245. *)
  2246. command kresd "$@"
  2247. esac
  2248. }
  2249. sudo()
  2250. {
  2251. case "$1" in
  2252. herd)
  2253. case "$2" in
  2254. start)
  2255. case "$3" in
  2256. xorg-server)
  2257. if [[ -e /var/run/slim-vt7.auth ]]
  2258. then
  2259. echo "Removing '/var/run/slim-vt7.auth' file."
  2260. command sudo rm /var/run/slim-vt7.auth
  2261. fi
  2262. if [[ -e /var/run/slim-vt7.lock ]]
  2263. then
  2264. echo "Removing '/var/run/slim-vt7.lock' file."
  2265. command sudo rm /var/run/slim-vt7.lock
  2266. fi
  2267. command sudo herd enable xorg-server
  2268. command sudo herd start xorg-server
  2269. ;;
  2270. *)
  2271. command sudo herd enable "${@:3}"
  2272. command sudo herd start "${@:3}"
  2273. ;;
  2274. esac
  2275. ;;
  2276. *)
  2277. command sudo herd "${@:2}"
  2278. ;;
  2279. esac
  2280. ;;
  2281. *)
  2282. command sudo "$@"
  2283. ;;
  2284. esac
  2285. }
  2286. PASSWORD_STORE_ENABLE_EXTENSIONS="true"
  2287. export PASSWORD_STORE_ENABLE_EXTENSIONS
  2288. PATH="${HOME}/bin":"${HOME}/.local/bin":"$(/usr/bin/env --ignore-environment sh --norc --noprofile -c 'unset PATH; export HOME=/home/oleg; export USER=oleg; source /etc/profile; printf "$PATH"')":"${HOME}/go/bin":"${HOME}/.npm-global/bin":/opt/gradle/bin:"${HOME}/perl5/bin":"${HOME}/.nix-profile/lib/openjdk/bin":"${HOME}/.nix-profile/bin":"$PATH"
  2289. export PATH
  2290. pactl_configure()
  2291. {
  2292. echo pactl load-module module-ladspa-sink sink_name=compressor-stereo plugin=sc4_1882 label=sc4 control=1,1.5,401,-30,20,5,30
  2293. echo pactl load-module module-null-sink media.class=Audio/Sink sink_name=obs-microphone channel_map=front-left,front-right
  2294. echo pactl load-module module-ladspa-sink sink_name=compressor-stereo-family-17 plugin=sc4_1882 label=sc4 control=1,1.5,401,-30,20,5
  2295. }
  2296. htop()
  2297. {
  2298. bash -c 'exec -a htop sudo htop'
  2299. }
  2300. if [[ -n $ALACRITTY_WINDOW_ID ]]
  2301. then
  2302. if [[ ${EUID} == 0 ]]
  2303. then
  2304. PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W\$\[\033[00m\] '
  2305. else
  2306. PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\$\[\033[00m\] '
  2307. fi
  2308. if type -p bat
  2309. then
  2310. # bat can be used as a colorizing pager for man, by setting the MANPAGER
  2311. # environment variable as documented here.
  2312. # https://github.com/sharkdp/bat#man
  2313. MANPAGER="sh -c 'col -bx | bat --theme=ansi -l man -p'"
  2314. export MANPAGER
  2315. MANROFFOPT="-c"
  2316. export MANROFFOPT
  2317. fi
  2318. fi