# Test for an interactive shell. There is no need to set anything # past this point for scp and rcp, and it's important to refrain from # outputting anything in those cases. if [[ $- != *i* ]] ; then # Shell is non-interactive. That's all, folks! return fi # {{{1 EXPORTS # XDG Base Directories export XDG_CONFIG_HOME="$HOME/.config" export XDG_DATA_HOME="$HOME/.local/share" export XDG_CACHE_HOME="$HOME/.cache" # Creates a user temporary directory. mkdir -p /tmp/$USER export TMPDIR=/tmp/$USER # Home subdirectories export GIT=$HOME/git export BIN=$HOME/.local/bin export MAIL=$HOME/mail export IMGS=$HOME/imgs export MUSIC=$HOME/music export DOWNLOADS=$HOME/downloads export OMNIA=$HOME/omnia export DOCUMENTS=$HOME/documents export NOTES=$DOCUMENTS/notes # Rust env variables export CARGO_HOME="$XDG_DATA_HOME"/cargo export RUSTUP_HOME="$XDG_DATA_HOME"/rustup if which rustc >/dev/null 2>&1 ; then export RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/library/ fi # Local path definitions export PATH=$BIN:$CARGO_HOME/bin:$HOME/.local/npm/bin:$PATH export NODE_PATH=$NODE_PATH:$HOME/.local/npm/lib/node_modules # Set default programs export TERMINAL=`which st` export EDITOR=`which nvim` export PAGER=`which less` export BROWSER=`which firefox-bin` export MAILCAPS=$XDG_CONFIG_HOME/mailcap/mailcap # Instruct less to use this control sequence every time it needs to # display bold text. For example, this alters headers and keywords in # man pages export LESS_TERMCAP_md="${yellow}" # Use System fonts for Java applications (added to fix Protegé font # problems) export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on" # History size for the in-memory list export HISTSIZE='1024'; # History size for the $HISTFILE export HISTFILESIZE=$HISTSIZE; # Omit duplicates and commands that begin with a whitespace from history export HISTCONTROL='ignoreboth'; # Make (relative) path relative to the cwd or the user's home (in this # order, in case of collisions) when using `cd` export CDPATH=".:$HOME:$GIT" # SSH connection if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then export SSH_SESSION=1 fi # FZF related config options export FZF_DEFAULT_COMMAND='rg --files --hidden --smart-case' # {{{1 ALIASES # Folder shortcuts alias dl="cd ~/downloads;clear" alias tmp='cd `mktemp -d`' # List all files colorized in long format alias ls="command ls -lF --color" # Same as `ls', but including hidden files alias la="command ls -laF --color" # Same as `ls', but clears the terminal screen first alias cls="clear;ls" # Same as `la', but clears the terminal screen first alias cla="clear;la" # Git-specific aliases alias gc="git checkout" alias gs="git status" alias glo="git log --color --decorate --oneline --graph" # Print each PATH entry on a separate line alias path='echo -e ${PATH//:/\\n}' # Other alias z="zathura" alias mpa="mpv --no-video" which rc-service >/dev/null 2>&1 && \ alias wifi="sudo rc-service wpa_supplicant" # {{{1 FUNCTIONS # Determine size of a file or total size of the current directory if no # argument is given filesize() { if du -b /dev/null > /dev/null 2>&1; then local arg=-sbh; else local arg=-sh; fi if [[ -n "$@" ]]; then du $arg -- "$@"; else du $arg .[^.]* ./*; fi; } # This is a better version of `tree` with hidden files and color # enabled, ignoring the `.git` directory, listing directories first. The # output gets piped into `less` with options to preserve color and line # numbers, unless the output is small enough for one screen. tree() { command tree -aC -I '.git' --dirsfirst "$@" | less -FRNX; } # Prints out a weather chart (automatically detects location if none # is passed). weather() { curl wttr.in/$1; } # {{{1 PROMPT # This is a variant of the bash prompt by Mathias Bynens at # https://github.com/mathiasbynens/dotfiles ## Gruvbox colors (dark version) ## https://github.com/morhetz/gruvbox black=$(tput setaf 0) red=$(tput setaf 9); green=$(tput setaf 10); yellow=$(tput setaf 11); blue=$(tput setaf 12); magenta=$(tput setaf 13); cyan=$(tput setaf 14); orange=$(tput setaf 166) white=$(tput setaf 15) grey=$(tput setaf 8) bold=$(tput bold); reset=$(tput sgr0); ## Builds a Git prompt of the from: ## ... on [●●●]↑ ## where the three dots indicate the presence of untracked, unstaged ## and uncommitted files. A little arrow notifies fi something needs ## to be pushed upstream. git_prompt() { local state=""; local symbol=">"; local branch="${bold}${magenta}"; # Check if the current directory is in a Git repository. if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then # check if the current directory is in .git before running git checks if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then # Ensure the index is up to date. git update-index --really-refresh -q &>/dev/null; state+="${white}[" # Check for untracked files. if [ -n "$(git ls-files --others --exclude-standard)" ]; then state+="${red}"; else state+="${grey}"; fi; state+="$symbol" # Check for unstashed files. if ! $(git diff-files --quiet --ignore-submodules --) ; then state+="${yellow}"; else state+="${grey}"; fi; state+="$symbol" # Check for uncommitted changes in the index. if ! $(git diff --quiet --ignore-submodules --cached); then state+="${green}"; else state+="${grey}" fi; state+="$symbol" state+="${white}]" # Check if tracked remote is up-to-date with the local # branch. # # NB: Output is redirected to /dev/null because calling `git # cherry` if no remote is set generates annoying messages # every time the prompt is refreshed. if [ -n "$(git cherry 2>/dev/null)" ]; then state+="${blue}↑" fi; fi; # Get the short symbolic ref. If HEAD is not a symbolic ref, get # the short SHA for the latest commit. branch+="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ git rev-parse --short HEAD 2> /dev/null || \ echo '(unknown)')"; echo -e " on ${branch} ${state}${reset}"; else return; fi; } job_count() { if [ -n "$(jobs -p)" ]; then echo -e " ($(jobs -p | wc -l))" fi } ## Prompt definition PS1="" ## Username PS1+="\[${bold}\]\[${green}\]\u\[${reset}\]" PS1+=" at " ## Hostname PS1+="\[${bold}\]\[${yellow}\]\h\[${reset}\]" PS1+=" in " ## Current working directory PS1+="\[${bold}\]\[${blue}\]\w\[${reset}\]" ## Git prompt PS1+="\[\$(git_prompt)\]" PS1+="\n" ## Lambda prompt PS1+="\[${bold}\]>\[${reset}\]" PS1+="\$(job_count) " export PS1; # {{{1 MISC ## Other options # Change cursor shape # 0 -> blinking block. # 1 -> blinking block (default). # 2 -> steady block. # 3 -> blinking underline. # 4 -> steady underline. # 5 -> blinking bar (xterm). # 6 -> steady bar (xterm). echo -ne "\e[6 q" # Vi mode for bash set -o vi; # Disable flow control (CTRL-S and CTRL-Q) stty -ixon # Automatically prepend 'cd' to directory used as command names shopt -s autocd; # Autocorrect typos in path names when using `cd` or pathnames shopt -s cdspell dirspell; # Check window size after each command and reset LINES and COLUMNS shopt -s checkwinsize; # Bash tries to save multiline commands as a single entry in the history shopt -s cmdhist lithist; # Dotfiles are included in the results of pathname expantion shopt -s dotglob; # '**' can be used to expand directory paths/files shopt -s globstar; # Enable extended glob obtions like `!(...)` or `+(...)` # For more info check `man bash` in the Pathname Expansion section. shopt -s extglob # Append to the history file, rather than overwriting it shopt -s histappend; # Does not try to perform autocompletion on an empty line shopt -s no_empty_cmd_completion; # Case-insensitive globbing (used in pathname expansion) shopt -s nocaseglob; # Network printers export mono3dup=Ricoh_Aficio_MP_5001_in_horizontal_duplex_mode_cups_cs_ox_ac_ # {{{1 ADDITIONAL FILES for file in $HOME/.bash/*.bash; do [ -r "$file" ] && [ -f "$file" ] && source "$file"; done; unset file;