dot_bashrc 75 KB

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