dotfiles

Obligatory dotfiles repo
git clone git://git.danielmoch.com/dotfiles.git
Log | Files | Refs

commit 647c7db4a8c4fe54ae70590541ddb1e4b0d2cd63
parent c47aeb04ebddbcb8cbf2208445f5bc1d4d1cf5da
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sat, 17 Feb 2018 10:16:44 -0500

Refactor shell initializations; add my completion

Diffstat:
M.bashrc | 108++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
M.profile | 14++++++++++++++
M.shrc | 6++++++
3 files changed, 110 insertions(+), 18 deletions(-)

diff --git a/.bashrc b/.bashrc @@ -12,7 +12,7 @@ GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 source "$HOME/.local/lib/sh/git-prompt.sh" -if [ x$TERM == xlinux ] +if [ $TERM = linux ] then usercolor='\[\033[01;34m\]' else @@ -21,23 +21,95 @@ fi export PS1=$usercolor'\u\[\033[m\]@\[\033[32m\]\h:\[\033[m\]\W\[\033[31m\]$(__git_ps1 " (%s)")\[\033[m\]\$ ' -if command -v brew > /dev/null 2>&1 -then - export HOMEBREW_NO_ANALYTICS=1 - export HOMEBREW_NO_INSECURE_REDIRECT=1 - export HOMEBREW_CASK_OPTS=--require-sha\ --appdir="$HOME/Applications" - export HOMEBREW_NO_AUTO_UPDATE=1 - export PATH="$(brew --prefix)/bin:$PATH" - if [ -f "$(brew --prefix)/etc/bash_completion" ] - then - source "$(brew --prefix)/etc/bash_completion" - fi -fi - [ -r "$BASH_COMPLETION" ] && source "$BASH_COMPLETION" unset BASH_COMPLETION -if [[ "$OSTYPE" == "darwin"* ]] -then - alias jackd="jackd -d coreaudio > /dev/null 2>&1 &" -fi +_my() +{ + local cur prev opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + selector="${COMP_WORDS[1]}" + opts="term lock wallpaper standby shutdown perms init open sound \ + kbopts screen brightness battery status i3status copy paste \ + netrc dotfiles cron login_async login" + + case "$selector" in + sound) + if [ "$prev" = "$selector" ] + then + opts="status set-sink-volume set-source-volume \ + set-sink-mute set-source-mute" + COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + elif [[ "$prev" == *"-mute" ]] + then + COMPREPLY=( $(compgen -W "toggle" -- $cur) ) + elif [ "$prev" = "set-sink-volume" ] + then + sinks=$(my sound list sinks short | cut -f 1) + COMPREPLY=( $(compgen -W "$sinks" -- $cur) ) + elif [ "$prev" = "set-source-volume" ] + then + sources=$(my sound list sources short | cut -f 1) + COMPREPLY=( $(compgen -W "$sources" -- $cur) ) + fi + return 0 + ;; + brightness) + opts="monitor kbd" + if [ "$prev" = "$selector" ] + then + COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + elif [[ "$opts" == *"$prev"* ]] + then + COMPREPLY=( $(compgen -W "inc dec" -- $cur) ) + fi + return 0 + ;; + battery) + opts="remaining total percent" + [ "$prev" = "$selector" ] && COMPREPLY=( $(compgen -W \ + "$opts" -- $cur) ) + return 0 + ;; + dotfiles) + opts="check update" + [ "$prev" = "$selector" ] && COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + return 0 + ;; + open) + _filedir + return 0 + ;; + init) + opts="-f -c" + [ "$prev" = "$selector" ] && COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + return 0 + ;; + netrc) + [ -f "$HOME/.netrc" ] || return 1 + + machines=$(cat "$HOME/.netrc" | grep ^machine | cut -d ' ' -f 2) + opts="login account password" + + if [ "$prev" = "$selector" ] + then + COMPREPLY=( $(compgen -W "$machines" -- $cur) ) + return 0 + elif [[ "$opts" == *"${COMP_WORDS[COMP_CWORD-1]}"* ]] + then + return 0 + else + COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + return 0 + fi + ;; + *) + ;; + esac + + [ "$cur" = "$selector" ] && COMPREPLY=($(compgen -W "$opts" -- $cur)) + return 0 +} +complete -F _my my diff --git a/.profile b/.profile @@ -28,6 +28,16 @@ else export LESSOPEN fi +if type brew > /dev/null 2>&1 +then + HOMEBREW_NO_ANALYTICS=1 + HOMEBREW_NO_INSECURE_REDIRECT=1 + HOMEBREW_CASK_OPTS=--require-sha\ --appdir="$HOME/Applications" + HOMEBREW_NO_AUTO_UPDATE=1 + export HOMEBREW_NO_ANALYTICS HOMEBREW_NO_INSECURE_REDIRECT + export HOMEBREW_CASK_OPTS HOMEBREW_NO_AUTO_UPDATE +fi + if type go > /dev/null 2>&1 then GOPATH="$HOME/.go" @@ -54,6 +64,10 @@ __addpath () __addpath "$HOME/.go/bin" __addpath "$HOME/.cargo/bin" +if type brew > /dev/null 2>&1 +then + __addpath "`brew --prefix`/bin" "before" +fi __addpath "$HOME/.local/bin" "before" unset __addpath diff --git a/.shrc b/.shrc @@ -57,6 +57,12 @@ then alias vim="vi" fi +case `uname -s` in + *Darwin*) + alias jackd="jackd -d coreaudio > /dev/null 2>&1 &" + ;; +esac + if type gpg-connect-agent > /dev/null 2>&1 then GPG_TTY=`tty`; export GPG_TTY