My dotfiles. Period.

main.bashrc 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  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}" urxvt
  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. -o '#[F]IXME:.*' -R "$@"
  268. }
  269. grepr() {
  270. #
  271. # Grep recursively, keeping numbers and ignoring common dirs
  272. #
  273. # Number one tool for refactoring!
  274. #
  275. local p=$1; shift
  276. grep --color -n --exclude-dir=".git" -e "$p" -R "$@"
  277. }
  278. grepr1() {
  279. #
  280. # Like grepr() but only list matching items in this directory
  281. #
  282. # Ie. list only files in current directory or names of subdirectories
  283. # where matches were found "somewhere".
  284. #
  285. grepr "$@" -l | cut -d/ -f1 | uniq
  286. }
  287. greph() {
  288. #
  289. # Grep through bash history
  290. #
  291. history | sed 's/^ *//; s/ / /' | cut -d' ' -f2- | grep "$@"
  292. }
  293. gitcd() {
  294. #
  295. # Deep in git repo, cd to the git root
  296. #
  297. cd "$(git rev-parse --show-toplevel)" || return 1
  298. }
  299. clsz() {
  300. #
  301. # Clear screen and move the prompt to bottom
  302. #
  303. tput clear; tput cup "$(tput lines)" 0
  304. }
  305. bcdiff() {
  306. #
  307. # Call bcompare only if objects actually differ
  308. #
  309. test $# -eq 2 && diff "$@" >/dev/null && return
  310. bcompare "$@" &
  311. }
  312. strip_colors() {
  313. #
  314. # Strip color codes from stdin
  315. #
  316. # Stolen from http://unix.stackexchange.com/a/4533/9365
  317. #
  318. sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g'
  319. }
  320. vims() {
  321. #
  322. # List Vim .swp files in a nice table
  323. #
  324. # **Note:** For this ro work, you need to set up Vim to
  325. # use same swap directory as assigned below. this can
  326. # be achieved by addoing section such as this to your
  327. # .vimrc:
  328. #
  329. # if isdirectory($HOME . '/.local/share/vim') == 0
  330. # :silent !mkdir -p ~/.vim/swap >/dev/null 2>&1
  331. # endif
  332. # set directory=./.vim-swap//
  333. # set directory+=~/.local/share/vim/swap//
  334. # set directory+=~/tmp//
  335. # set directory+=.
  336. #
  337. # Call this after crash or poweroff to remind yourself what
  338. # files you were editing before fact. Example:
  339. #
  340. # 2015-07-10 06:10:48.603953758 +0200 ~/TODO.todo
  341. #
  342. # This should make it easier to recover after a little
  343. # disaster.
  344. #
  345. local swap="$HOME/.local/share/vim/swap"
  346. #shellcheck disable=SC1117
  347. find "$swap" -type f -print0 \
  348. | xargs -0 -r stat -c "%y %n" \
  349. | sed "
  350. s| $swap/| |
  351. s|%|/|g
  352. s|.swp$||
  353. s| $HOME| ~|
  354. s| \(..:..\):[^ ]* +.... | \\1 |
  355. " \
  356. | sort \
  357. | tac
  358. }
  359. fixnl() {
  360. #
  361. # Fix newlines in stdin and pass to stdout
  362. #
  363. # Note: We need to read whole stdin; this cannot work
  364. # for infinite stream.
  365. #
  366. # Fix annoying cases:
  367. #
  368. # * If multi-line text is missing newline at the
  369. # end---add the missing newline.
  370. #
  371. # * If -c is passed, and single-line text does have
  372. # a newline at the end, remove it.
  373. #
  374. # This will not touch properly terminated multi-line texts,
  375. # or zero-line texts (ie. oly chars with no newline at all).
  376. #
  377. local arg=$1 # argument passed
  378. local cache # cache to keep stream in
  379. local nlcount # count of newlines in the stream
  380. local lastchr # hex dump (2-digit, lowercase) of last char
  381. local single=keep # single-line streams:
  382. # keep: do nothing
  383. # chop: drop last char if it's a LF
  384. case $arg in
  385. -c|--chop-single) single=chop ;;
  386. esac
  387. cache="$(mktemp -t fixnl.XXXXXXXX)"
  388. cat >"$cache"
  389. nlcount=$(<"$cache" wc -l)
  390. lastchr=$(<"$cache" tail -c1 | hexdump -e '"%02x"')
  391. case $nlcount:$lastchr:$single in
  392. 0:??:*) cat "$cache" ;; # 'abc' => keep as is
  393. 1:0a:chop) head -c -1 "$cache" ;; # 'abc\n' => -c passed: chop!
  394. 1:0a:keep) cat "$cache" ;; # 'abc\n' => keep as is
  395. *:0a:*) cat "$cache" ;; # 'a\nb\nc\n' => keep as is
  396. *:??:*) cat "$cache"; echo ;; # 'a\nb\nc' => add the missing NL
  397. esac
  398. rm "$cache"
  399. }
  400. nlfor() {
  401. #
  402. # Replace $1 (or blank space) with newlines and fix final newline
  403. #
  404. # Shorthand for commonly used tr syntax. Example:
  405. #
  406. # $ echo "$PATH" | nlat :
  407. # /foo
  408. # /bar
  409. # $
  410. #
  411. # is almost like `tr : '\n'` except that it is a bit easier
  412. # to type and fixes the annoying problem with missing
  413. # newline at the end of the replaced string.
  414. #
  415. local char=$1
  416. test -n "$char" || char='[:blank:]'
  417. tr "$char" '\n' \
  418. | fixnl
  419. }
  420. nljoin() {
  421. #
  422. # Join lines with $1 (or space)
  423. #
  424. # Shorthand for commonly used tr syntax. Example:
  425. #
  426. # $ { echo foo; echo bar; } | nljoin :
  427. #
  428. # is almost like `tr '\n' :` except that it is a bit easier
  429. # to type and fixes the annoying problem with extraneous
  430. # newline/colon at the end of final string.
  431. #
  432. local char=$1
  433. test -n "$char" || char=' '
  434. tr '\n' "$char" \
  435. | sed "s/$char*$//" \
  436. | fixnl -c
  437. }
  438. urle() {
  439. #
  440. # Encode or decode (if $1 is '-d') message on stdin as URL encode
  441. #
  442. local fn=quote
  443. case $1 in
  444. -d) fn=unquote ;;
  445. -*) echo 'usage: urle [-d] <text' >&2; return 2 ;;
  446. esac
  447. python3 -c "import sys; from urllib.parse import $fn; print($fn(sys.stdin.read()));"
  448. }
  449. qpr() {
  450. #
  451. # Encode or decode (if $1 is '-d') message on stdin as Quoted Printable
  452. #
  453. local fn=encode
  454. case $1 in
  455. -d) fn=decode ;;
  456. -*) echo 'usage: qpr [-d] <text' >&2; return 2 ;;
  457. esac
  458. perl -MMIME::QuotedPrint -pe "\$_=MIME::QuotedPrint::$fn(\$_);"
  459. }
  460. xop() {
  461. #
  462. # Common clipboard operations with fixnl() on top
  463. #
  464. local op=$1
  465. local arg=${2:-/dev/stdin}
  466. case $op in
  467. aa) <<<"$arg" fixnl -c | xclip -selection clipboard -i ;;
  468. a) <<<"$arg" fixnl -c | xclip -i ;;
  469. ii) <"$arg" fixnl -c | xclip -selection clipboard -i ;;
  470. i) <"$arg" fixnl -c | xclip -i ;;
  471. oo) <"$arg" xclip -selection clipboard -o | fixnl ;;
  472. o) <"$arg" xclip -o | fixnl ;;
  473. *) return 2 ;;
  474. esac
  475. }
  476. xt() {
  477. #
  478. # Type out selection clipboard content using xdotool
  479. #
  480. local stime=${1:-3}
  481. local body
  482. snore "$stime"
  483. body=$(xo)
  484. xdotool type "$body"
  485. }
  486. xtt() {
  487. #
  488. # Type out C-C clipboard content using xdotool
  489. #
  490. local stime=${1:-3}
  491. local body
  492. snore "$stime"
  493. body=$(xoo)
  494. xdotool type "$body"
  495. }
  496. xdl() {
  497. #
  498. # Download URL from primary clipboard to path $1
  499. #
  500. local dest=$1
  501. local url
  502. url=$(xo)
  503. _xdl "$dest" "$url"
  504. }
  505. xxdl() {
  506. #
  507. # Download URL from C-C clipboard to path $1
  508. #
  509. local dest=$1
  510. local url
  511. url=$(xoo)
  512. _xdl "$dest" "$url"
  513. }
  514. _xdl() {
  515. #
  516. # Download URL from primary clipboard to path $1
  517. #
  518. local dest=$1
  519. local url=$2
  520. local es
  521. test -n "$dest" || return 2
  522. test -f "$dest" && return 2
  523. test -n "$url" || return 2
  524. curl -fsSL "$url" >"$dest"; es=$?
  525. bb
  526. return $es
  527. }
  528. xod() {
  529. #
  530. # Like mktemp but get the content from clipboard
  531. #
  532. # Dump xo in a file named $1 somewhere in /tmp; echo the path
  533. # usage: scp $(xod useful_name.txt) eg:some/shared/place
  534. # instead of:
  535. #
  536. # xo > useful_name.txt
  537. # scp useful_name.txt eg:some/shared/place
  538. # rm useful_name.txt
  539. #
  540. local name="${1:-clipboard_dump.txt}"
  541. local tmp
  542. tmp=$(mktemp -d -t "xod.XXXXXXXX")
  543. xclip -o > "$tmp/$name"
  544. echo "$tmp/$name"
  545. }
  546. xood() {
  547. #
  548. # Just like xod() but using xoo (i.e. 'clipboard' clipboard)
  549. #
  550. local name="${1:-clipboard_dump.txt}"
  551. local tmp
  552. tmp=$(mktemp -d -t "xood.XXXXXXXX")
  553. xclip -selection clipboard -o > "$tmp/$name"
  554. echo "$tmp/$name"
  555. }
  556. xl() {
  557. #
  558. # Show primary clipboard in less(1)
  559. #
  560. xop o | less -S
  561. }
  562. xxl() {
  563. #
  564. # Show C-C clipboard in less(1)
  565. #
  566. xop oo | less -S
  567. }
  568. xvxx() {
  569. #
  570. # Edit text in primary clipboard and save it to C-C clipboard
  571. #
  572. # Ideal for editing snippets in browser-based editors: during editing,
  573. # select the text, open terminal, call `xvxx`, edit the text, move
  574. # back to the browser and paste it over the old (still selected) text.
  575. # That's it, no need to make up and save temporary files.
  576. #
  577. # If you quickly realize you need to re-edit the text, use xxvxx().
  578. #
  579. xop o | vipe | xop ii
  580. }
  581. xcp() {
  582. #
  583. # Copy paths of $@ to clipboard
  584. #
  585. local path
  586. find "$@" -maxdepth 0 -mindepth 0 \
  587. | while read -r path; do
  588. readlink -e "$path"
  589. done \
  590. | xop i
  591. }
  592. xpst() {
  593. #
  594. # Paste paths from clipboard
  595. #
  596. { xop o; echo; } \
  597. | while read -r path; do
  598. echo "path='$path'" >&2
  599. test -e "$path" || {
  600. echo "does not exist: $path"
  601. continue
  602. }
  603. cp -ar "$path" .
  604. done
  605. }
  606. xpst_l() {
  607. #
  608. # Symlink paths from clipboard, with relative paths
  609. #
  610. { xop o; echo; } \
  611. | while read -r path; do
  612. echo "path='$path'" >&2
  613. test -e "$path" || {
  614. echo "does not exist: $path"
  615. continue
  616. }
  617. ln -sr "$path" .
  618. done
  619. }
  620. xpst_la() {
  621. #
  622. # Symlink paths from clipboard, with absolute paths
  623. #
  624. { xop o; echo; } \
  625. | while read -r path; do
  626. echo "path='$path'" >&2
  627. test -e "$path" || {
  628. echo "does not exist: $path"
  629. continue
  630. }
  631. ln -s "$path" .
  632. done
  633. }
  634. xvb() {
  635. #
  636. # Edit text in primary clipboard and run it using bash
  637. #
  638. xop o | vipe | bash
  639. }
  640. xxvb() {
  641. #
  642. # Edit text in C-C clipboard and run it using bash
  643. #
  644. xop oo | vipe | bash
  645. }
  646. vxx() {
  647. #
  648. # Edit text on stdin and save it to C-C clipboard
  649. #
  650. # Ideal for editing outut of command before pasting ot to browser
  651. # or another GUI application. Run the command with `vxx`, edit
  652. # the text, move back to the application and paste it.
  653. #
  654. # If you quickly realize you need to re-edit the text, use xxvxx().
  655. #
  656. vipe | xop ii
  657. }
  658. xcxx() {
  659. #
  660. # Filter text in primary clipboard using command $@ and save it to C-C clipboard
  661. #
  662. # Similar to xvxx() but instead of interactive editing, provided filter
  663. # command is run.
  664. #
  665. local cmd=("$@")
  666. xop o | "${cmd[@]}" | xop ii
  667. return "${PIPESTATUS[1]}"
  668. }
  669. xtrans() {
  670. #
  671. # Translate text in primary clipboard using code $1 and output it
  672. #
  673. # Similar to xcxx but assumes code snippet, and prints the result
  674. # to make it easier to check it visually.
  675. #
  676. local code=$1
  677. test $# -gt 1 && code=$(printf '%q ' "$@")
  678. # echo >&2 "debug:code=$code"
  679. local es
  680. xop o | bash -c "$code" | xop ii
  681. es="${PIPESTATUS[1]}"
  682. xop oo >&2
  683. echo >&2
  684. return "$es"
  685. }
  686. xfromc() {
  687. #
  688. # Get text using code $1 and output it
  689. #
  690. # Similar to xtrans but assumes code snippet, and prints the result
  691. # to make it easier to check it visually.
  692. #
  693. local code=$1
  694. test $# -gt 1 && code=$(printf '%q ' "$@")
  695. echo >&2 "debug:code=$code"
  696. local es
  697. bash -c "$code" | xop ii
  698. es="${PIPESTATUS[0]}"
  699. xop oo >&2
  700. echo >&2
  701. return "$es"
  702. }
  703. vx() {
  704. #
  705. # Edit stdin and save it to primary clipboard
  706. #
  707. # Ideal for selecting snippets of output of arbitrary commands.
  708. # select the text, open terminal, call `xvx`, edit the text, move
  709. # back to the browser and paste it over the old (still selected) text.
  710. # That's it, no need to make up and save temporary files.
  711. #
  712. vipe | xop i
  713. }
  714. xxvxx() {
  715. #
  716. # Edit text in C-C clipboard and save it back
  717. #
  718. xop oo | vipe | xop ii
  719. }
  720. yt2ogg() {
  721. #
  722. # Download YouTube video as vorbis audio
  723. #
  724. local url=$1
  725. youtube-dl -x --audio-format vorbis "$url"
  726. }
  727. yum_hasbin() {
  728. #
  729. # Ask yum who has bin $1 (and make the output actually readable)
  730. #
  731. local bname
  732. for bname in "$@";
  733. do
  734. case $bname in
  735. */*) dnf provides "$bname" ;;
  736. *) dnf provides "*/bin/$bname" ;;
  737. esac \
  738. | grep '^.' \
  739. | grep -E '^[[:alnum:]_:.-]+ :'
  740. done
  741. }
  742. cal() {
  743. #
  744. # cal with the proper version pick
  745. #
  746. local cal_v
  747. local cal_es
  748. cal_v=$(command cal -V 2>/dev/null); cal_es=$?
  749. case $cal_es:$cal_v in
  750. 0:cal\ from\ util-linux\ 2.*)
  751. command cal --color=always --monday --week "$@"
  752. ;;
  753. 64:*)
  754. command cal -M "$@"
  755. ;;
  756. esac
  757. }
  758. ### .... ###
  759. ### BASH ###
  760. ### '''' ###
  761. HISTCONTROL=ignoredups:erasedups
  762. # shopt -s histappend
  763. # PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
  764. HISTIGNORE="$HISTIGNORE:ls:ll:la:cd"
  765. HISTIGNORE="$HISTIGNORE:git st"
  766. HISTIGNORE="$HISTIGNORE:se *:sc *"
  767. HISTSIZE=33333
  768. HISTFILESIZE=33333
  769. HISTTIMEFORMAT='%F %T '
  770. GLOBIGNORE=.:..
  771. # shopt -s histverify
  772. # some more aliases
  773. alias cls='clear'
  774. alias czkrates='czkrates -v'
  775. alias ll='ls -lh'
  776. alias lla='ls -lha'
  777. alias lr='ll -lhrt'
  778. alias open='xdg-open'
  779. alias diff='colordiff -u'
  780. alias dmesg='dmesg --time-format iso'
  781. alias pad4='sed -e "/./s/^/ /"'
  782. alias mkittool='mkittool -v'
  783. alias grep='grep --color'
  784. alias sc='se --direction encz.cz'
  785. alias taskm='task modify'
  786. alias tasks='task rc.context:none'
  787. alias ts='ts "%F %T"'
  788. alias lsblk='lsblk -o +UUID,LABEL'
  789. alias pstree='pstree -h'
  790. alias virsh='virsh --connect qemu:///system'
  791. alias wttr='curl -s "wttr.in/?1&n&q"'
  792. alias xi='xop i'
  793. alias xii='xop ii'
  794. alias xa='xop a'
  795. alias xaa='xop aa'
  796. alias xo='xop o'
  797. alias xoo='xop oo'
  798. alias reboot="echo -n . ; sync ; echo -n . ; sync ; echo -n . ; systemctl reboot"
  799. alias poweroff="echo -n . ; sync ; echo -n . ; sync ; echo -n . ; systemctl poweroff"
  800. x4xx() {
  801. #
  802. # Pad text from primary clipboard with 4 spaces; save to C-C clipboard
  803. #
  804. # ...that is, for inclusion as Markdown verbatim text.
  805. #
  806. xop oo | pad4 | xop ii
  807. }
  808. x4x() {
  809. #
  810. # Pad text from primary clipboard with 4 spaces; save back
  811. #
  812. # ...that is, for inclusion as Markdown verbatim text.
  813. #
  814. xop -o | pad4 | xop i
  815. }
  816. BASHUM__RV_TMP="/tmp/bashum-rv"
  817. mkdir -p "$BASHUM__RV_TMP"
  818. ### ...... ###
  819. ### OTHERS ###
  820. ### '''''' ###
  821. export LC_COLLATE=C # make sort upper first
  822. export EDITOR=vim
  823. export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
  824. export LESS=' -R '
  825. export NEATY=color
  826. export PRETTY=color
  827. export PRETTY_DEBUG_EXCLUDE=inigrep
  828. export MDVIMB__CONVERTER=cmark
  829. export MDVIMB__STYLE=darkzen # pergamen
  830. export MYPY_CACHE_DIR="$HOME/.cache/mypy/the_darn_cache"
  831. #shellcheck disable=SC2034
  832. {
  833. GIT_PS1_SHOWDIRTYSTATE=true
  834. GIT_PS1_SHOWUNTRACKEDFILES=true
  835. __SATURNIN_COMPLETE_DEBUG=true
  836. GIT_DISABLED_COMMANDS="$HOME/.gittum/disabled-commands"
  837. }
  838. export GIT_PAGER='less -S'
  839. # disable mounting things like SFTP to ~/.gvfs when accessed
  840. # via GIO (used by nautilus etc.)
  841. export GVFS_DISABLE_FUSE=1
  842. # disable the terrible beep sound (only for X; for tty?, blacklist pcspkr)
  843. xhost >& /dev/null && xset b off
  844. # get rid of those .pyc files once and for all
  845. export PYTHONDONTWRITEBYTECODE=1
  846. ssh-add -l >& /dev/null || ssh-add