My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. #!/bin/bash
  2. ## hack to workaround Fedora/Red Hat bug 878428
  3. #shellcheck disable=SC1091
  4. test -f /usr/share/git-core/contrib/completion/git-prompt.sh \
  5. && . /usr/share/git-core/contrib/completion/git-prompt.sh
  6. #######################################################
  7. ### things to do BEFORE host/user-specific settings ###
  8. #######################################################
  9. ### .... ###
  10. ### SUBZ ###
  11. ### '''' ###
  12. prepend() {
  13. #
  14. # pre-pend $2 to filename $1
  15. #
  16. local path=$1
  17. local prefix=$2
  18. local dirpath
  19. local filename
  20. local abspath
  21. abspath=$(readlink -f "$path")
  22. dirpath=$(dirname "$abspath")
  23. filename=$(basename "$abspath")
  24. echo mv "$path" "$dirpath/$prefix-$filename"
  25. }
  26. smv() {
  27. #
  28. # scp but rm the source
  29. #
  30. local src=$1
  31. local dst=$2
  32. test $# -eq 2 || {
  33. echo "i can only 2 argz!" >&2
  34. return 2
  35. }
  36. scp "$src" "$dst" && rm "$src"
  37. }
  38. smvr() {
  39. #
  40. # smv but recursive
  41. #
  42. local src=$1
  43. local dst=$2
  44. test $# -eq 2 || {
  45. echo "i can only 2 argz!" >&2
  46. return 2
  47. }
  48. scp -r "$src" "$dst" && rm -r "$src"
  49. }
  50. snore() {
  51. #
  52. # Sleep loudly-ish for $1 time
  53. #
  54. local stime=${1:-0}
  55. test "$stime" == 0 || echo -e "sleeping for $BASHUM_COLOR_LGREEN$stime$BASHUM_COLOR_NORMAL"
  56. sleep "$stime"
  57. }
  58. dotsleep() {
  59. #
  60. # Sleep with dots for $1 seconds
  61. #
  62. local secs=$1
  63. echo -e "sleeping for $BASHUM_COLOR_LGREEN$secs$BASHUM_COLOR_NORMAL seconds"
  64. local secs_togo=$secs
  65. while test "$secs_togo" -gt 0; do
  66. sleep 1
  67. echo -n .
  68. ((secs_togo--))
  69. done
  70. echo
  71. }
  72. bb() {
  73. #
  74. # Ring the bell after $1 time of sleep
  75. #
  76. local stime=${1:-0}
  77. snore "$stime"
  78. printf '\a'
  79. }
  80. spec_cksources() {
  81. #
  82. # Check Source?: URL's in RPM spec file $1
  83. #
  84. local file=$1
  85. local hdr
  86. local url
  87. rpmspec -P "$file" \
  88. | grep -E 'Source[0-9]+: *http' \
  89. | while read -r hdr url; do
  90. echo -n "$hdr: $url .."
  91. curl -fsSL -I "$url" >/dev/null || {
  92. echo fail
  93. return 1
  94. }
  95. echo ok
  96. done
  97. }
  98. nn() {
  99. #
  100. # Ring the bell and send notification $1 after $2 time
  101. #
  102. local msg=${1:-this is done}
  103. local stime=$2
  104. bb "$stime"
  105. echo -e "hey, $BASHUM_COLOR_LRED$msg$BASHUM_COLOR_NORMAL"
  106. notify-send -a 'nn()' "hey, $msg"
  107. }
  108. pp() {
  109. #
  110. # Ring the bell and send notification $1 and pause
  111. #
  112. local msg=${1:-this is done}
  113. bb
  114. echo -e "hey, \033[1;31m$msg\033[1;0m!"
  115. notify-send -a 'pp()' "hey, $msg"
  116. read -r junk -p "Press Enter to continue"
  117. }
  118. wrep() {
  119. #
  120. # Print each line on STDIN $1 times horizontally
  121. #
  122. echo >&2 "use sdup -w instead!"
  123. local rep=${1:-1}; shift
  124. local delim=${1:-" "}; shift
  125. local line
  126. local n
  127. while read -r line; do
  128. local head=true
  129. n=$rep
  130. while test "$n" -gt 0;
  131. do
  132. $head || echo -n "$delim"
  133. $head && head=false
  134. echo -n "$line"
  135. ((n--))
  136. done
  137. echo
  138. done
  139. }
  140. lrep() {
  141. #
  142. # Print each line on STDIN $1 times
  143. #
  144. echo >&2 "use sdup -l instead!"
  145. local rep=${1:-1}; shift
  146. local line
  147. local n
  148. while read -r line; do
  149. n=$rep
  150. while test "$n" -gt 0;
  151. do
  152. echo "$line"
  153. ((n--))
  154. done
  155. done
  156. }
  157. prep() {
  158. #
  159. # Print STDIN $1 times
  160. #
  161. echo >&2 "use sdup instead!"
  162. local rep=${1:-1}; shift
  163. local data
  164. data=$(cat)
  165. n=$rep
  166. while test "$n" -gt 0;
  167. do
  168. echo "$data"
  169. echo
  170. ((n--))
  171. done
  172. }
  173. dt() {
  174. #
  175. # Open $1 new terminals
  176. #
  177. __bashum_run_n "${1:-1}" alacritty
  178. }
  179. dT() {
  180. #
  181. # Open $1 new alterminals
  182. #
  183. __bashum_run_n "${1:-1}" xfce4-terminal
  184. }
  185. hr() {
  186. #
  187. # Make horizontal ruler
  188. #
  189. local i
  190. local line
  191. for i in $(seq 1 "$COLUMNS"); do
  192. case $((i%10)) in
  193. 0) line+='#' ;;
  194. *) line+='-' ;;
  195. esac
  196. done
  197. echo "$line"
  198. echo "$line"
  199. echo "$line"
  200. }
  201. __bashum_run_n() {
  202. #
  203. # Run $2.. in background $1 times
  204. #
  205. local n=${1:-1}; shift
  206. while test "$n" -gt 0;
  207. do
  208. "$@" &
  209. ((n--))
  210. done
  211. }
  212. twice() {
  213. #
  214. # Run $@ two times
  215. #
  216. "$@"
  217. "$@"
  218. }
  219. ckyaml() {
  220. #
  221. # Check if YAML file $1 is loadable
  222. #
  223. local yfile=$1
  224. test -n "$yfile" || { echo "usage: ckyaml FILE.yaml"; return 2; }
  225. python -c 'import yaml; import sys; print(yaml.load(sys.stdin)["this"])' <"$yfile"
  226. }
  227. git() {
  228. #
  229. # /usr/bin/git wrapper just to disable dangerous commands
  230. #
  231. # In particular, `git-am` is a a close typo of my favorite
  232. # aliases `ap` (`git-add --patch`) and `cm` (`git-commit`)
  233. # but it's dangerous to call by accident as it destroys
  234. # workdir changes.
  235. #
  236. if grep -Fwqse "$1" "$GIT_DISABLED_COMMANDS"; then
  237. echo "You don't want this." >&2
  238. return 1
  239. else
  240. command git "$@"
  241. fi
  242. }
  243. grepcl() {
  244. #
  245. # Grep in common chat log files
  246. #
  247. # The order is from older apps to newer as I was moving towards
  248. # weechat.
  249. #
  250. grep "$@" -R \
  251. "$HOME/.config/xchat2/xchatlogs" \
  252. "$HOME/.config/xchat2/scrollback" \
  253. "$HOME/.config/hexchat/logs" \
  254. "$HOME/.config/hexchat/scrollback" \
  255. "$HOME/.local/share/weechat/logs.old" \
  256. "$HOME/.local/share/weechat/logs"
  257. }
  258. grepfx() {
  259. #
  260. # Grep recursively for technical debt
  261. #
  262. # '[F]' hack to avoid matching self
  263. #
  264. grep --color -n \
  265. --exclude-dir 'utils' \
  266. --exclude-dir '.git' \
  267. --exclude-dir '.zig-cache' \
  268. -o '#[F]IXME:.*' -R "$@"
  269. }
  270. grepr() {
  271. #
  272. # Grep recursively, keeping numbers and ignoring common dirs
  273. #
  274. # Number one tool for refactoring!
  275. #
  276. local p=$1; shift
  277. grep --color -n --exclude-dir=".git" --exclude-dir ".zig-cache" --exclude-dir "zig-out" -e "$p" -R "$@"
  278. }
  279. grepr1() {
  280. #
  281. # Like grepr() but only list matching items in this directory
  282. #
  283. # Ie. list only files in current directory or names of subdirectories
  284. # where matches were found "somewhere".
  285. #
  286. grepr "$@" -l | cut -d/ -f1 | uniq
  287. }
  288. greph() {
  289. #
  290. # Grep through bash history
  291. #
  292. history | sed 's/^ *//; s/ / /' | cut -d' ' -f2- | grep "$@"
  293. }
  294. gitcd() {
  295. #
  296. # Deep in git repo, cd to the git root
  297. #
  298. cd "$(git rev-parse --show-toplevel)" || return 1
  299. }
  300. clsz() {
  301. #
  302. # Clear screen and move the prompt to bottom
  303. #
  304. tput clear; tput cup "$(tput lines)" 0
  305. }
  306. bcdiff() {
  307. #
  308. # Call bcompare only if objects actually differ
  309. #
  310. test $# -eq 2 && diff "$@" >/dev/null && return
  311. bcompare "$@" &
  312. }
  313. strip_colors() {
  314. #
  315. # Strip color codes from stdin
  316. #
  317. # Stolen from http://unix.stackexchange.com/a/4533/9365
  318. #
  319. sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g'
  320. }
  321. vims() {
  322. #
  323. # List Vim .swp files in a nice table
  324. #
  325. # **Note:** For this ro work, you need to set up Vim to
  326. # use same swap directory as assigned below. this can
  327. # be achieved by addoing section such as this to your
  328. # .vimrc:
  329. #
  330. # if isdirectory($HOME . '/.local/share/vim') == 0
  331. # :silent !mkdir -p ~/.vim/swap >/dev/null 2>&1
  332. # endif
  333. # set directory=./.vim-swap//
  334. # set directory+=~/.local/share/vim/swap//
  335. # set directory+=~/tmp//
  336. # set directory+=.
  337. #
  338. # Call this after crash or poweroff to remind yourself what
  339. # files you were editing before fact. Example:
  340. #
  341. # 2015-07-10 06:10:48.603953758 +0200 ~/TODO.todo
  342. #
  343. # This should make it easier to recover after a little
  344. # disaster.
  345. #
  346. local swap="$HOME/.local/share/vim/swap"
  347. #shellcheck disable=SC1117
  348. find "$swap" -type f -print0 \
  349. | xargs -0 -r stat -c "%y %n" \
  350. | sed "
  351. s| $swap/| |
  352. s|%|/|g
  353. s|.swp$||
  354. s| $HOME| ~|
  355. s| \(..:..\):[^ ]* +.... | \\1 |
  356. " \
  357. | sort \
  358. | tac
  359. }
  360. fixnl() {
  361. #
  362. # Fix newlines in stdin and pass to stdout
  363. #
  364. # Note: We need to read whole stdin; this cannot work
  365. # for infinite stream.
  366. #
  367. # Fix annoying cases:
  368. #
  369. # * If multi-line text is missing newline at the
  370. # end---add the missing newline.
  371. #
  372. # * If -c is passed, and single-line text does have
  373. # a newline at the end, remove it.
  374. #
  375. # This will not touch properly terminated multi-line texts,
  376. # or zero-line texts (ie. oly chars with no newline at all).
  377. #
  378. local arg=$1 # argument passed
  379. local cache # cache to keep stream in
  380. local nlcount # count of newlines in the stream
  381. local lastchr # hex dump (2-digit, lowercase) of last char
  382. local single=keep # single-line streams:
  383. # keep: do nothing
  384. # chop: drop last char if it's a LF
  385. case $arg in
  386. -c|--chop-single) single=chop ;;
  387. esac
  388. cache="$(mktemp -t fixnl.XXXXXXXX)"
  389. cat >"$cache"
  390. nlcount=$(<"$cache" wc -l)
  391. lastchr=$(<"$cache" tail -c1 | hexdump -e '"%02x"')
  392. case $nlcount:$lastchr:$single in
  393. 0:??:*) cat "$cache" ;; # 'abc' => keep as is
  394. 1:0a:chop) head -c -1 "$cache" ;; # 'abc\n' => -c passed: chop!
  395. 1:0a:keep) cat "$cache" ;; # 'abc\n' => keep as is
  396. *:0a:*) cat "$cache" ;; # 'a\nb\nc\n' => keep as is
  397. *:??:*) cat "$cache"; echo ;; # 'a\nb\nc' => add the missing NL
  398. esac
  399. rm "$cache"
  400. }
  401. nlfor() {
  402. #
  403. # Replace $1 (or blank space) with newlines and fix final newline
  404. #
  405. # Shorthand for commonly used tr syntax. Example:
  406. #
  407. # $ echo "$PATH" | nlat :
  408. # /foo
  409. # /bar
  410. # $
  411. #
  412. # is almost like `tr : '\n'` except that it is a bit easier
  413. # to type and fixes the annoying problem with missing
  414. # newline at the end of the replaced string.
  415. #
  416. local char=$1
  417. test -n "$char" || char='[:blank:]'
  418. tr "$char" '\n' \
  419. | fixnl
  420. }
  421. nljoin() {
  422. #
  423. # Join lines with $1 (or space)
  424. #
  425. # Shorthand for commonly used tr syntax. Example:
  426. #
  427. # $ { echo foo; echo bar; } | nljoin :
  428. #
  429. # is almost like `tr '\n' :` except that it is a bit easier
  430. # to type and fixes the annoying problem with extraneous
  431. # newline/colon at the end of final string.
  432. #
  433. local char=$1
  434. test -n "$char" || char=' '
  435. tr '\n' "$char" \
  436. | sed "s/$char*$//" \
  437. | fixnl -c
  438. }
  439. urle() {
  440. #
  441. # Encode or decode (if $1 is '-d') message on stdin as URL encode
  442. #
  443. local fn=quote
  444. case $1 in
  445. -d) fn=unquote ;;
  446. -*) echo 'usage: urle [-d] <text' >&2; return 2 ;;
  447. esac
  448. python3 -c "import sys; from urllib.parse import $fn; print($fn(sys.stdin.read()));"
  449. }
  450. qpr() {
  451. #
  452. # Encode or decode (if $1 is '-d') message on stdin as Quoted Printable
  453. #
  454. local fn=encode
  455. case $1 in
  456. -d) fn=decode ;;
  457. -*) echo 'usage: qpr [-d] <text' >&2; return 2 ;;
  458. esac
  459. perl -MMIME::QuotedPrint -pe "\$_=MIME::QuotedPrint::$fn(\$_);"
  460. }
  461. xop() {
  462. #
  463. # Common clipboard operations with fixnl() on top
  464. #
  465. local op=$1
  466. local arg=${2:-/dev/stdin}
  467. case $op in
  468. aa) <<<"$arg" fixnl -c | xclip -selection clipboard -i ;;
  469. a) <<<"$arg" fixnl -c | xclip -i ;;
  470. ii) <"$arg" fixnl -c | xclip -selection clipboard -i ;;
  471. i) <"$arg" fixnl -c | xclip -i ;;
  472. oo) <"$arg" xclip -selection clipboard -o | fixnl ;;
  473. o) <"$arg" xclip -o | fixnl ;;
  474. *) return 2 ;;
  475. esac
  476. }
  477. xt() {
  478. #
  479. # Type out selection clipboard content using xdotool
  480. #
  481. local stime=${1:-3}
  482. local body
  483. snore "$stime"
  484. body=$(xo)
  485. xdotool type "$body"
  486. }
  487. xtt() {
  488. #
  489. # Type out C-C clipboard content using xdotool
  490. #
  491. local stime=${1:-3}
  492. local body
  493. snore "$stime"
  494. body=$(xoo)
  495. xdotool type "$body"
  496. }
  497. xdl() {
  498. #
  499. # Download URL from primary clipboard to path $1
  500. #
  501. local dest=$1
  502. local url
  503. url=$(xo)
  504. _xdl "$dest" "$url"
  505. }
  506. xxdl() {
  507. #
  508. # Download URL from C-C clipboard to path $1
  509. #
  510. local dest=$1
  511. local url
  512. url=$(xoo)
  513. _xdl "$dest" "$url"
  514. }
  515. _xdl() {
  516. #
  517. # Download URL from primary clipboard to path $1
  518. #
  519. local dest=$1
  520. local url=$2
  521. local es
  522. test -n "$dest" || return 2
  523. test -f "$dest" && return 2
  524. test -n "$url" || return 2
  525. curl -fsSL "$url" >"$dest"; es=$?
  526. bb
  527. return $es
  528. }
  529. xod() {
  530. #
  531. # Like mktemp but get the content from clipboard
  532. #
  533. # Dump xo in a file named $1 somewhere in /tmp; echo the path
  534. # usage: scp $(xod useful_name.txt) eg:some/shared/place
  535. # instead of:
  536. #
  537. # xo > useful_name.txt
  538. # scp useful_name.txt eg:some/shared/place
  539. # rm useful_name.txt
  540. #
  541. local name="${1:-clipboard_dump.txt}"
  542. local tmp
  543. tmp=$(mktemp -d -t "xod.XXXXXXXX")
  544. xclip -o > "$tmp/$name"
  545. echo "$tmp/$name"
  546. }
  547. xood() {
  548. #
  549. # Just like xod() but using xoo (i.e. 'clipboard' clipboard)
  550. #
  551. local name="${1:-clipboard_dump.txt}"
  552. local tmp
  553. tmp=$(mktemp -d -t "xood.XXXXXXXX")
  554. xclip -selection clipboard -o > "$tmp/$name"
  555. echo "$tmp/$name"
  556. }
  557. xl() {
  558. #
  559. # Show primary clipboard in less(1)
  560. #
  561. xop o | less -S
  562. }
  563. xxl() {
  564. #
  565. # Show C-C clipboard in less(1)
  566. #
  567. xop oo | less -S
  568. }
  569. xvxx() {
  570. #
  571. # Edit text in primary clipboard and save it to C-C clipboard
  572. #
  573. # Ideal for editing snippets in browser-based editors: during editing,
  574. # select the text, open terminal, call `xvxx`, edit the text, move
  575. # back to the browser and paste it over the old (still selected) text.
  576. # That's it, no need to make up and save temporary files.
  577. #
  578. # If you quickly realize you need to re-edit the text, use xxvxx().
  579. #
  580. xop o | vipe | xop ii
  581. }
  582. xcp() {
  583. #
  584. # Copy paths of $@ to clipboard
  585. #
  586. local path
  587. test $# -gt 0 || return 0
  588. find "$@" -maxdepth 0 -mindepth 0 \
  589. | while read -r path; do
  590. readlink -e "$path"
  591. done \
  592. | xop i
  593. }
  594. xpst() {
  595. #
  596. # Paste paths from clipboard
  597. #
  598. local target_path="${1:-.}"
  599. test -d "$target_path" || {
  600. echo >&2 "no such directory: $target_path"
  601. return 2
  602. }
  603. { xop o; echo; } \
  604. | while read -r path; do
  605. echo "path='$path'" >&2
  606. test -e "$path" || {
  607. echo "does not exist: $path"
  608. continue
  609. }
  610. cp -ar "$path" "$target_path"
  611. done
  612. }
  613. xpst_l() {
  614. #
  615. # Symlink paths from clipboard, with relative paths
  616. #
  617. { xop o; echo; } \
  618. | while read -r path; do
  619. echo "path='$path'" >&2
  620. test -e "$path" || {
  621. echo "does not exist: $path"
  622. continue
  623. }
  624. ln -sr "$path" .
  625. done
  626. }
  627. xpst_la() {
  628. #
  629. # Symlink paths from clipboard, with absolute paths
  630. #
  631. { xop o; echo; } \
  632. | while read -r path; do
  633. echo "path='$path'" >&2
  634. test -e "$path" || {
  635. echo "does not exist: $path"
  636. continue
  637. }
  638. ln -s "$path" .
  639. done
  640. }
  641. xvb() {
  642. #
  643. # Edit text in primary clipboard and run it using bash
  644. #
  645. xop o | vipe | bash
  646. }
  647. xxvb() {
  648. #
  649. # Edit text in C-C clipboard and run it using bash
  650. #
  651. xop oo | vipe | bash
  652. }
  653. vxx() {
  654. #
  655. # Edit text on stdin and save it to C-C clipboard
  656. #
  657. # Ideal for editing outut of command before pasting ot to browser
  658. # or another GUI application. Run the command with `vxx`, edit
  659. # the text, move back to the application and paste it.
  660. #
  661. # If you quickly realize you need to re-edit the text, use xxvxx().
  662. #
  663. vipe | xop ii
  664. }
  665. xcxx() {
  666. #
  667. # Filter text in primary clipboard using command $@ and save it to C-C clipboard
  668. #
  669. # Similar to xvxx() but instead of interactive editing, provided filter
  670. # command is run.
  671. #
  672. local cmd=("$@")
  673. xop o | "${cmd[@]}" | xop ii
  674. return "${PIPESTATUS[1]}"
  675. }
  676. xtrans() {
  677. #
  678. # Translate text in primary clipboard using code $1 and output it
  679. #
  680. # Similar to xcxx but assumes code snippet, and prints the result
  681. # to make it easier to check it visually.
  682. #
  683. local code=$1
  684. test $# -gt 1 && code=$(printf '%q ' "$@")
  685. # echo >&2 "debug:code=$code"
  686. local es
  687. xop o | bash -c "$code" | xop ii
  688. es="${PIPESTATUS[1]}"
  689. xop oo >&2
  690. echo >&2
  691. return "$es"
  692. }
  693. xfromc() {
  694. #
  695. # Get text using code $1 and output it
  696. #
  697. # Similar to xtrans but assumes code snippet, and prints the result
  698. # to make it easier to check it visually.
  699. #
  700. local code=$1
  701. test $# -gt 1 && code=$(printf '%q ' "$@")
  702. echo >&2 "debug:code=$code"
  703. local es
  704. bash -c "$code" | xop ii
  705. es="${PIPESTATUS[0]}"
  706. xop oo >&2
  707. echo >&2
  708. return "$es"
  709. }
  710. vx() {
  711. #
  712. # Edit stdin and save it to primary clipboard
  713. #
  714. # Ideal for selecting snippets of output of arbitrary commands.
  715. # select the text, open terminal, call `xvx`, edit the text, move
  716. # back to the browser and paste it over the old (still selected) text.
  717. # That's it, no need to make up and save temporary files.
  718. #
  719. vipe | xop i
  720. }
  721. xxvxx() {
  722. #
  723. # Edit text in C-C clipboard and save it back
  724. #
  725. xop oo | vipe | xop ii
  726. }
  727. yt2ogg() {
  728. #
  729. # Download YouTube video as vorbis audio
  730. #
  731. local url=$1
  732. youtube-dl -x --audio-format vorbis "$url"
  733. }
  734. yum_hasbin() {
  735. #
  736. # Ask yum who has bin $1 (and make the output actually readable)
  737. #
  738. local bname
  739. for bname in "$@";
  740. do
  741. case $bname in
  742. */*) dnf provides "$bname" ;;
  743. *) dnf provides "*/bin/$bname" ;;
  744. esac \
  745. | grep '^.' \
  746. | grep -E '^[[:alnum:]_:.-]+ :'
  747. done
  748. }
  749. cal() {
  750. #
  751. # cal with the proper version pick
  752. #
  753. local cal_v
  754. local cal_es
  755. cal_v=$(command cal -V 2>/dev/null); cal_es=$?
  756. case $cal_es:$cal_v in
  757. 0:cal\ from\ util-linux\ 2.*)
  758. command cal --color=always --monday --week "$@"
  759. ;;
  760. 64:*)
  761. command cal -M "$@"
  762. ;;
  763. 127:*)
  764. echo >&2 "cal(): cal command is not installed"
  765. return 127
  766. ;;
  767. *)
  768. echo >&2 "cal(): error: cal_es=$cal_es, cal_v=$cal_v"
  769. return 5
  770. ;;
  771. esac
  772. }
  773. ### .... ###
  774. ### BASH ###
  775. ### '''' ###
  776. HISTCONTROL=ignoredups:erasedups
  777. # shopt -s histappend
  778. # PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
  779. HISTIGNORE="$HISTIGNORE:ls:ll:la:cd"
  780. HISTIGNORE="$HISTIGNORE:git st"
  781. HISTIGNORE="$HISTIGNORE:se *:sc *"
  782. HISTSIZE=33333
  783. HISTFILESIZE=33333
  784. HISTTIMEFORMAT='%F %T '
  785. GLOBIGNORE=.:..
  786. # shopt -s histverify
  787. # some more aliases
  788. alias cls='clear'
  789. alias czkrates='czkrates -v'
  790. alias ll='ls -lh'
  791. alias lla='ls -lha'
  792. alias lr='ll -lhrt'
  793. alias open='xdg-open'
  794. alias diff='colordiff -u'
  795. alias dmesg='dmesg --time-format iso'
  796. alias pad4='sed -e "/./s/^/ /"'
  797. alias mkittool='mkittool -v'
  798. alias grep='grep --color'
  799. alias sc='se --direction encz.cz'
  800. alias taskm='task modify'
  801. alias tasks='task rc.context:none'
  802. alias ts='ts "%F %T"'
  803. alias lsblk='lsblk -o +UUID,LABEL'
  804. alias pstree='pstree -h'
  805. alias virsh='virsh --connect qemu:///system'
  806. alias xi='xop i'
  807. alias xii='xop ii'
  808. alias xa='xop a'
  809. alias xaa='xop aa'
  810. alias xo='xop o'
  811. alias xoo='xop oo'
  812. alias reboot="echo -n . ; sync ; echo -n . ; sync ; echo -n . ; systemctl reboot"
  813. alias poweroff="echo -n . ; sync ; echo -n . ; sync ; echo -n . ; systemctl poweroff"
  814. alias pydoc='pydoc3'
  815. alias readelf='readelf -W'
  816. x4xx() {
  817. #
  818. # Pad text from primary clipboard with 4 spaces; save to C-C clipboard
  819. #
  820. # ...that is, for inclusion as Markdown verbatim text.
  821. #
  822. xop oo | pad4 | xop ii
  823. }
  824. x4x() {
  825. #
  826. # Pad text from primary clipboard with 4 spaces; save back
  827. #
  828. # ...that is, for inclusion as Markdown verbatim text.
  829. #
  830. xop -o | pad4 | xop i
  831. }
  832. BASHUM__RV_TMP="/tmp/bashum-rv"
  833. mkdir -p "$BASHUM__RV_TMP"
  834. ### ...... ###
  835. ### OTHERS ###
  836. ### '''''' ###
  837. export LC_COLLATE=C # make sort upper first
  838. export EDITOR=vim
  839. export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
  840. export LESS=' -R '
  841. export NEATY=color
  842. export PRETTY=color
  843. export PRETTY_DEBUG_EXCLUDE=inigrep
  844. export MDVIMB__CONVERTER=cmark
  845. export MDVIMB__STYLE=darkzen # pergamen
  846. export MYPY_CACHE_DIR="$HOME/.cache/mypy/the_darn_cache"
  847. #shellcheck disable=SC2034
  848. {
  849. GIT_PS1_SHOWDIRTYSTATE=true
  850. GIT_PS1_SHOWUNTRACKEDFILES=true
  851. __SATURNIN_COMPLETE_DEBUG=true
  852. GIT_DISABLED_COMMANDS="$HOME/.gittum/disabled-commands"
  853. }
  854. export GIT_PAGER='less -S'
  855. # disable mounting things like SFTP to ~/.gvfs when accessed
  856. # via GIO (used by nautilus etc.)
  857. export GVFS_DISABLE_FUSE=1
  858. # disable the terrible beep sound (only for X; for tty?, blacklist pcspkr)
  859. xhost >& /dev/null && xset b off
  860. # get rid of those .pyc files once and for all
  861. export PYTHONDONTWRITEBYTECODE=1
  862. export ZIG_LOCAL_CACHE_DIR="$HOME/.cache/zig-local"
  863. export ZK_ROOT="$HOME/.local/pim/zk"
  864. export ZKZIG_ROOT="$HOME/.local/pim/zk"