My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/bash
  2. ## hack to workaround Fedora/Red Hat bug 878428
  3. test -f /usr/share/git-core/contrib/completion/git-prompt.sh \
  4. && . /usr/share/git-core/contrib/completion/git-prompt.sh
  5. #######################################################
  6. ### things to do BEFORE host/user-specific settings ###
  7. #######################################################
  8. ### .... ###
  9. ### SUBZ ###
  10. ### '''' ###
  11. git() {
  12. #
  13. # /usr/bin/git wrapper just to disable dangerous commands
  14. #
  15. # In particular, `git-am` is a a close typo of my favorite
  16. # aliases `ap` (`git-add --patch`) and `cm` (`git-commit`)
  17. # but it's dangerous to call by accident as it destroys
  18. # workdir changes.
  19. #
  20. if grep -Fwqse "$1" "$GIT_DISABLED_COMMANDS"; then
  21. echo "You don't want this." >&2
  22. return 1
  23. else
  24. command git "$@"
  25. fi
  26. }
  27. grepr() {
  28. #
  29. # Grep recursively, keeping numbers and ignoring common dirs
  30. #
  31. # Number one tool for refactoring!
  32. #
  33. local p=$1; shift
  34. grep --color -n --exclude-dir=".git" -e "$p" -r "$@"
  35. }
  36. greph() {
  37. #
  38. # Grep through bash history
  39. #
  40. history | sed 's/^ *//; s/ / /' | cut -d' ' -f2- | grep "$@"
  41. }
  42. gitcd() {
  43. #
  44. # Deep in git repo, cd to the git root
  45. #
  46. cd "$(git rev-parse --show-toplevel)"
  47. }
  48. clsz() {
  49. #
  50. # Clear screen and move the prompt to bottom
  51. #
  52. tput clear; tput cup "$(tput lines)" 0
  53. }
  54. bcdiff() {
  55. #
  56. # Call bcompare only if objects actually differ
  57. #
  58. test $# -eq 2 && diff "$@" >/dev/null && return
  59. bcompare "$@" &
  60. }
  61. vims() {
  62. #
  63. # Show "abandoned" Vim .swp files in a nice table
  64. #
  65. # Call this after crash or poweroff to get back and recover
  66. # files open before the fact. Example:
  67. #
  68. # 2015-07-10 06:10:48.603953758 +0200 ~/TODO.todo
  69. #
  70. # Depends on .swp settings defined in my mydots repo.
  71. #
  72. local swap="$HOME/.local/share/vim/swap"
  73. find "$swap" -type f -print0 \
  74. | xargs -0 -r stat -c "%y %n" \
  75. | sed "
  76. s| $swap/| |
  77. s|%|/|g
  78. s|.swp$||
  79. s| $HOME| ~|
  80. s| \(..:..\):[^ ]* +.... | \\1 |
  81. " \
  82. | sort \
  83. | tac
  84. }
  85. xod() {
  86. #
  87. # Like mktemp but get the content from clipboard
  88. #
  89. # Dump xo in a file named $1 somewhere in /tmp; echo the path
  90. # usage: scp $(xod useful_name.txt) eg:some/shared/place
  91. # instead of xo>useful_name.txt; scp useful_name.txt eg:some/shared/place; rm useful_name.txt
  92. #
  93. local name="${1:-clipboard_dump.txt}"
  94. local tmp=$(mktemp -d -t "xod.XXXXXXXX")
  95. xclip -o > "$tmp/$name"
  96. echo "$tmp/$name"
  97. }
  98. xood() {
  99. #
  100. # Just like xod() but using xoo (i.e. 'clipboard' clipboard)
  101. #
  102. local name="${1:-clipboard_dump.txt}"
  103. local tmp=$(mktemp -d -t "xood.XXXXXXXX")
  104. xclip -selection clipboard -o > "$tmp/$name"
  105. echo "$tmp/$name"
  106. }
  107. yum_hasbin() {
  108. #
  109. # Ask yum who has bin $1 (and make the output actually readable)
  110. #
  111. local bname
  112. for bname in "$@";
  113. do
  114. yum provides "*bin/$bname" \
  115. | grep '^.' \
  116. | grep -E '^[0-9a-zA-Z_:.-]+ :'
  117. done
  118. }
  119. ### .... ###
  120. ### BASH ###
  121. ### '''' ###
  122. HISTCONTROL=erasedups
  123. HISTIGNORE="$HISTIGNORE:ls:ll:la:cd"
  124. HISTIGNORE="$HISTIGNORE:git dc:git st"
  125. #export HISTIGNORE="$HISTIGNORE:se *:sc *"
  126. HISTSIZE=-1
  127. HISTFILESIZE=100000
  128. GLOBIGNORE=.:..
  129. shopt -s histverify
  130. # some more aliases
  131. alias cal='cal -m'
  132. alias cls='clear'
  133. alias ll='ls -lh'
  134. alias lla='ls -lha'
  135. alias open='gnome-open'
  136. alias diff='diff -u'
  137. alias dmesg='dmesg --time-format iso'
  138. alias pad4='sed -e "/./s/^/ /"'
  139. alias grep='grep --color --binary-files=without-match'
  140. alias sc='se --direction=encz.cz'
  141. alias ts='ts "%F %T"'
  142. alias lsblk='lsblk -o +UUID,LABEL'
  143. alias virsh='virsh --connect qemu:///system'
  144. alias xaa='xclip -o | audit2allow'
  145. alias xi='xclip -i'
  146. alias xii='xclip -selection clipboard -i'
  147. alias xo='xclip -o'
  148. alias xoo='xclip -selection clipboard -o'
  149. RV_TMP="/tmp/bash-rv"
  150. mkdir -p "$RV_TMP"
  151. ### ...... ###
  152. ### OTHERS ###
  153. ### '''''' ###
  154. export LC_COLLATE=C # make sort upper first
  155. export SHELLFU_PRETTY=color
  156. export SHELLFU_DEBUG_EXCLUDE=inigrep
  157. # make green git bash trinket even cooler
  158. GIT_PS1_SHOWDIRTYSTATE=true
  159. GIT_PS1_SHOWUNTRACKEDFILES=true
  160. GIT_DISABLED_COMMANDS="$HOME/.gittum/disabled-commands"
  161. export GIT_PAGER='less -S'
  162. # disable mounting things like SFTP to ~/.gvfs when accessed
  163. # via GIO (used by nautilus etc.)
  164. export GVFS_DISABLE_FUSE=1
  165. # disable the terrible beep sound (only for X; for tty?, blacklist pcspkr)
  166. [[ ${!DISPLAY[@]} ]] && xset b off
  167. # get rid of those .pyc files once and for all
  168. export PYTHONDONTWRITEBYTECODE=1
  169. ssh-add -l >& /dev/null || ssh-add