Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
6.1 KiB

8 years ago
11 years ago
  1. # Paths: {{{
  2. #
  3. # This accounts for, at least:
  4. #
  5. # - a custom Firefox install
  6. # - some bin dirs in my homedir
  7. # - golang, ruby
  8. #
  9. # .sh_common is sourced by ~/bin/xmonad.start to provide for entire x session
  10. # getting these vars.
  11. #
  12. # Beware that other modifications to path might be made in .zshrc or .bashrc
  13. # It's a tangled mess which certainly warrants a TODO.
  14. export GOPATH=~/code/go
  15. export GOROOT=/usr/local/go
  16. export GEM_HOME=~/gems
  17. export P1K3_ROOT=~/workspace/p1k3
  18. # export PATH=~/firefox:~/bin:~/notes/bin:~/.xmonad:~/.local/bin/:$GEM_HOME/bin:$GOPATH/bin:$PATH
  19. # The below stuff may break and need reverted on Debian - above line contains ~/bin, use that one -- bpb 2019-03-10:
  20. # Put a dir at the start of path, IFF it's not already in the path:
  21. prepend_to_path () {
  22. local dir="$1"
  23. if [[ -d "${dir}" ]]; then
  24. if [[ ":$PATH:" != *"${dir}"* ]]; then
  25. export PATH="${dir}:${PATH}"
  26. fi
  27. fi
  28. }
  29. prepend_to_path "$GOROOT/bin" # golang
  30. prepend_to_path "$GOPATH/bin" # golang
  31. prepend_to_path "$GEM_HOME/bin" # ruby
  32. prepend_to_path "$HOME/.cargo/bin" # rust
  33. prepend_to_path ~/.local/bin
  34. prepend_to_path ~/.xmonad
  35. prepend_to_path ~/notes/bin
  36. prepend_to_path ~/firefox
  37. prepend_to_path ~/bin
  38. # }}}
  39. # General environment / config: {{{
  40. # Debian stuff - define DEBFULLNAME, DEBEMAIL here:
  41. if [ -f ~/.sh_common_debconfig ]; then
  42. . ~/.sh_common_debconfig
  43. fi
  44. # Explicitly set default editor:
  45. export EDITOR=`which vim`
  46. # Configure less(1):
  47. export LESS='-FiRSX'
  48. # Configure fzf fuzzyfinder:
  49. export FZF_CTRL_R_OPTS='-e' # exact match by default - see fzf(1)
  50. # For mediawiki/core/docker-compose.yml
  51. export MW_DOCKER_UID=$(id -u)
  52. export MW_DOCKER_GID=$(id -g)
  53. # }}}
  54. # Aliases, various and sundry: {{{
  55. alias ac='apt-cache'
  56. alias agu='sudo apt-get update && sudo apt-get upgrade'
  57. alias c='commandlog'
  58. alias fd='fdfind'
  59. alias g='git'
  60. alias gitsu='git submodule sync && git submodule update'
  61. alias m='make'
  62. alias mk='mark'
  63. alias mka='mark add'
  64. alias s='sudo'
  65. alias v='vim'
  66. alias vt='vim `todaydir`'
  67. # How big is the terminal?
  68. alias dim='echo $(tput cols)x$(tput lines)'
  69. # vi life:
  70. alias :e='nvim'
  71. alias :q='exit'
  72. alias :wq='exit'
  73. alias :r='cat'
  74. # }}}
  75. # Functions: {{{
  76. # p1k3 navigation:
  77. function p {
  78. cd "$P1K3_ROOT"
  79. }
  80. function ct {
  81. cd $(todaydir)
  82. }
  83. if type exa &> /dev/null; then
  84. # If exa is installed, replace the traditional ls aliases with exa
  85. # invocations.
  86. function l {
  87. exa --group-directories-first $@
  88. }
  89. function ll {
  90. exa --group-directories-first -l --git $@
  91. }
  92. function la {
  93. # This would typically be `ls -A`, for "almost all", which excludes . and ..
  94. # - exa appears to do that by default, and so doesn't have an -A option
  95. exa --group-directories-first -a $@
  96. }
  97. function lal {
  98. # ls -Al
  99. exa --group-directories-first -al --git $@
  100. }
  101. function lah {
  102. # ls -Alh
  103. # exa uses human-readable sizes by default, so doesn't have the -h flag.
  104. exa --group-directories-first -al --git $@
  105. }
  106. else
  107. # No exa, so set up traditional ls aliases as functions.
  108. function l {
  109. ls --group-directories-first --color -CF $@
  110. }
  111. function ll {
  112. ls --group-directories-first -l --color $@
  113. }
  114. function la {
  115. # Almost all - exclude . and ..:
  116. ls --group-directories-first -A $@
  117. }
  118. function lal {
  119. ls --group-directories-first -Al $@
  120. }
  121. function lah {
  122. ls --group-directories-first -Alh $@
  123. }
  124. fi
  125. # Get a persistent directory history menu in fzf - originally written for dmenu
  126. # and inspired by jholland at:
  127. #
  128. # http://hints.macworld.com/article.php?story=20050806202859392
  129. #
  130. # I get the feeling that there's probably a more idiomatic way to do what
  131. # I want here, but for the moment it's nice.
  132. #
  133. # See: https://p1k3.com/2016/5/17/
  134. function h {
  135. if [ ! -z "$@" ]; then
  136. cd $(tail -2500 ~/.directory_history | tac | unsorted-unique | fzf --no-sort --height=50% -q $@)
  137. else
  138. cd $(tail -2500 ~/.directory_history | tac | unsorted-unique | fzf --no-sort --height=50%)
  139. fi
  140. }
  141. function b {
  142. if [ ! -z "$@" ]; then
  143. echo $(realpath "$@") >> ~/.directory_bookmarks
  144. else
  145. cd $(sort ~/.directory_bookmarks | uniq | fzf --no-sort --height=50%)
  146. fi
  147. }
  148. # Create a directory (if it doesn't exist) and cd to it:
  149. function mcd {
  150. mkdir -p $1 && cd $1
  151. }
  152. # Use official git prompt, if it exists, or fall back to
  153. # parse_git_branch:
  154. if [ -f "$HOME/.git-prompt.sh" ]; then
  155. GIT_PS1_SHOWCOLORHINTS=1
  156. GIT_PS1_SHOWUNTRACKEDFILES=1
  157. GIT_PS1_SHOWDIRTYSTATE=1
  158. GIT_PS1_SHOWUPSTREAM="auto verbose"
  159. # shellcheck source=/home/brennen/.git-prompt.sh
  160. . "$HOME/.git-prompt.sh"
  161. else
  162. # Emulate __git_ps1 interface which takes 2 params - before part
  163. # and after part:
  164. function __git_ps1 {
  165. PS1="$1 $(parse_git_branch)$2"
  166. }
  167. fi
  168. # Get some information about a git repo
  169. function parse_git_branch {
  170. # if [ ! -z "$has_git_prompt" ]; then
  171. # __git_ps1
  172. # return
  173. # fi
  174. # Formerly:
  175. # ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  176. # echo "("${ref#refs/heads/}") "
  177. # Originally borrowed from:
  178. # https://github.com/robacarp/config_files/commit/5d983240d509bf4f7815ed822c0e868ccce08a79
  179. git_status=$(git status --porcelain -b 2> /dev/null) || return
  180. echo $git_status | awk '
  181. BEGIN {
  182. status["untracked"] = 0
  183. status["mods"] = 0
  184. branch_status = ""
  185. }
  186. $0 ~ /.*\[.*\]$/ {
  187. branch_status = " " $3 " " $4
  188. }
  189. $1 ~ /##/ {
  190. gsub(/\.\.\..*/, "")
  191. branch_name = $2
  192. }
  193. $1 ~ /\?\?/ { status["untracked"] ++ }
  194. $1 ~ /M/ { status["mods"] ++ }
  195. END {
  196. printf "(%s m%i/u%i%s) ", branch_name, status["mods"], status["untracked"], branch_status
  197. }
  198. '
  199. }
  200. # Render a simple horizontal rule / title bar in the terminal. Again, a
  201. # variation on robacarp:
  202. # https://robacarp.io/2018/07/19/bash-hr-function-to-draw-a-line-across-the-terminal.html
  203. function titlebar {
  204. # Text written into the horizontal rule, left justified
  205. text=${1:-}
  206. length=$(echo "$text" | wc -m)
  207. # set the color
  208. echo -e -n "\033[30;47m"
  209. # print the message
  210. echo -n "$text"
  211. # finish the line across the console
  212. cols=$(expr "$(tput cols)" - $length)
  213. printf " %${cols}s"
  214. # clear the background color and start a new line
  215. echo -e "\033[0m"
  216. }
  217. # }}}