dot_bashrc 74 KB

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