123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- # Paths: {{{
- #
- # This accounts for, at least:
- #
- # - a custom Firefox install
- # - some bin dirs in my homedir
- # - golang, ruby
- #
- # .sh_common is sourced by ~/bin/xmonad.start to provide for entire x session
- # getting these vars.
- #
- # Beware that other modifications to path might be made in .zshrc or .bashrc
- # It's a tangled mess which certainly warrants a TODO.
-
- export GOPATH=~/code/go
- export GOROOT=/opt/go
- export GEM_HOME=~/gems
- export P1K3_ROOT=~/workspace/p1k3
-
- # export PATH=~/firefox:~/bin:~/notes/bin:~/.xmonad:~/.local/bin/:$GEM_HOME/bin:$GOPATH/bin:$PATH
- # The below stuff may break and need reverted on Debian - above line contains ~/bin, use that one -- bpb 2019-03-10:
-
- # Put a dir at the start of path, IFF it's not already in the path:
- prepend_to_path () {
- local dir="$1"
-
- if [[ -d "${dir}" ]]; then
- if [[ ":$PATH:" != *"${dir}"* ]]; then
- export PATH="${dir}:${PATH}"
- fi
- fi
- }
- prepend_to_path "$GOROOT/bin" # golang
- prepend_to_path "$GOPATH/bin" # golang
- prepend_to_path "$GEM_HOME/bin" # ruby
- prepend_to_path "$HOME/.cargo/bin" # rust
- prepend_to_path ~/.local/bin
- prepend_to_path ~/.xmonad
- prepend_to_path ~/notes/bin
- prepend_to_path ~/firefox
- prepend_to_path ~/bin
-
- # }}}
-
- # General environment / config: {{{
- # Debian stuff - define DEBFULLNAME, DEBEMAIL here:
- if [ -f ~/.sh_common_debconfig ]; then
- . ~/.sh_common_debconfig
- fi
-
- # Explicitly set default editor:
- export EDITOR=`which vim`
-
- # Configure less(1):
- export LESS='-FiRSX'
-
- # Configure fzf fuzzyfinder:
- export FZF_CTRL_R_OPTS='-e' # exact match by default - see fzf(1)
-
- # }}}
-
- # Aliases, various and sundry: {{{
-
- alias ac='apt-cache'
- alias agu='sudo apt-get update && sudo apt-get upgrade'
- alias c='commandlog'
- alias fd='fdfind'
- alias g='git'
- alias gitsu='git submodule sync && git submodule update'
- alias m='make'
- alias mk='mark'
- alias mka='mark add'
- alias s='sudo'
- alias v='vim'
- alias vt='vim `todaydir`'
-
- # How big is the terminal?
- alias dim='echo $(tput cols)x$(tput lines)'
-
- # vi life:
- alias :e='vim'
- alias :q='exit'
- alias :wq='exit'
- alias :r='cat'
-
- # }}}
-
- # Functions: {{{
-
- # p1k3 navigation:
- function p {
- cd "$P1K3_ROOT"
- }
-
- function ct {
- cd $(todaydir)
- }
-
- if type exa &> /dev/null; then
- # If exa is installed, replace the traditional ls aliases with exa
- # invocations.
-
- function l {
- exa $@
- }
-
- function ll {
- exa -l --git $@
- }
-
- function la {
- # This would typically be `ls -A`, for "almost all", which excludes . and ..
- # - exa appears to do that by default, and so doesn't have an -A option
- exa -a $@
- }
-
- function lal {
- # ls -Al
- exa -al --git $@
- }
-
- function lah {
- # ls -Alh
- # exa uses human-readable sizes by default, so doesn't have the -h flag.
- exa -al --git $@
- }
- else
- # No exa, so set up traditional ls aliases as functions.
- function l {
- ls -CF $@
- }
-
- function ll {
- ls -l $@
- }
-
- function la {
- # Almost all - exclude . and ..:
- ls -A $@
- }
-
- function lal {
- ls -Al $@
- }
-
- function lah {
- ls -Alh $@
- }
- fi
-
- # Get a persistent directory history menu in fzf - originally written for dmenu
- # and inspired by jholland at:
- #
- # http://hints.macworld.com/article.php?story=20050806202859392
- #
- # I get the feeling that there's probably a more idiomatic way to do what
- # I want here, but for the moment it's nice.
- #
- # See: https://p1k3.com/2016/5/17/
- function h {
- if [ ! -z "$@" ]; then
- cd $(tail -2500 ~/.directory_history | tac | unsorted-unique | fzf --no-sort --height=50% -q $@)
- else
- cd $(tail -2500 ~/.directory_history | tac | unsorted-unique | fzf --no-sort --height=50%)
- fi
- }
-
- function b {
- if [ ! -z "$@" ]; then
- echo $(realpath "$@") >> ~/.directory_bookmarks
- else
- cd $(tail -3000 ~/.directory_bookmarks | tac | unsorted-unique | fzf --no-sort --height=50%)
- fi
- }
-
- # Create a directory (if it doesn't exist) and cd to it:
- function mcd {
- mkdir -p $1 && cd $1
- }
-
- # Get some information about a git repo - useful for
- function parse_git_branch {
- # Formerly:
- # ref=$(git symbolic-ref HEAD 2> /dev/null) || return
- # echo "("${ref#refs/heads/}") "
-
- # Originally borrowed from:
- # https://github.com/robacarp/config_files/commit/5d983240d509bf4f7815ed822c0e868ccce08a79
- git_status=$(git status --porcelain -b 2> /dev/null) || return
-
- echo $git_status | awk '
- BEGIN {
- status["untracked"] = 0
- status["mods"] = 0
- branch_status = ""
- }
- $0 ~ /.*\[.*\]$/ {
- branch_status = " " $3 " " $4
- }
- $1 ~ /##/ {
- gsub(/\.\.\..*/, "")
- branch_name = $2
- }
- $1 ~ /\?\?/ { status["untracked"] ++ }
- $1 ~ /M/ { status["mods"] ++ }
-
- END {
- printf "(%s m%i/u%i%s) ", branch_name, status["mods"], status["untracked"], branch_status
- }
- '
- }
-
- # Render a simple horizontal rule / title bar in the terminal. Again, a
- # variation on robacarp:
- # https://robacarp.io/2018/07/19/bash-hr-function-to-draw-a-line-across-the-terminal.html
- function titlebar {
- # Text written into the horizontal rule, left justified
- text=${1:-}
- length=$(echo "$text" | wc -m)
-
- # set the color
- echo -e -n "\033[30;47m"
-
- # print the message
- echo -n "$text"
-
- # finish the line across the console
- cols=$(expr "$(tput cols)" - $length)
- printf " %${cols}s"
-
- # clear the background color and start a new line
- echo -e "\033[0m"
- }
-
- # }}}
|