dot_bashrc 74 KB

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