From e5a914b7dd093d67ea78a56cd1d6be7de42fbe36 Mon Sep 17 00:00:00 2001 From: Alexander Karle Date: Wed, 25 Apr 2018 20:07:54 -0400 Subject: [PATCH] Adding basic bash scripts for systems w/o zsh I've decided that a minimal bash config that I feel comfy in is both (1) good to have around and (2) a good learning experience about the terminal! I've done a good bit of "best practice" research for putting together these files (specifically bashrc vs bash_profile...). For now, I'll continue to use oh-my-zsh because of its awesome interactive features! --- bash/aliases | 9 +++++++++ bash/bash_path | 9 +++++++++ bash/bash_profile | 13 +++++++++++++ bash/bash_prompt | 38 ++++++++++++++++++++++++++++++++++++++ bash/bashrc | 8 ++++++++ 5 files changed, 77 insertions(+) create mode 100644 bash/aliases create mode 100644 bash/bash_path create mode 100644 bash/bash_profile create mode 100644 bash/bash_prompt create mode 100644 bash/bashrc diff --git a/bash/aliases b/bash/aliases new file mode 100644 index 0000000..ab51c41 --- /dev/null +++ b/bash/aliases @@ -0,0 +1,9 @@ +# ls aliases +alias l='ls -lAh' +alias ll='ls -lh' + +# Git aliases +alias ga='git add' +alias gp='git push' +alias gst='git status' +alias gl='git log --stat' diff --git a/bash/bash_path b/bash/bash_path new file mode 100644 index 0000000..ee40b4b --- /dev/null +++ b/bash/bash_path @@ -0,0 +1,9 @@ +# Add Homebrew `/usr/local/bin` and User `~/bin` to the `$PATH` +PATH=/usr/local/bin:$PATH +PATH=$HOME/bin:$PATH + +# Add cargo to path +PATH="$HOME/.cargo/bin:$PATH" + +# Export it! +export PATH diff --git a/bash/bash_profile b/bash/bash_profile new file mode 100644 index 0000000..059e878 --- /dev/null +++ b/bash/bash_profile @@ -0,0 +1,13 @@ +# sourced by login shells (not interactive shells) +# Example: +# - ssh to Linux --> run bash_profile on login +# - open new tmux window --> run bashrc +# +# Exception: +# ** On OSX bash_profile is run by terminal emulators (new tabs, etc) ** +# +# Takeaway: +# ** Write preferences in bashrc, source it from bash_profile ** +if [ -r ~/.bashrc ]; then + source ~/.bashrc +fi diff --git a/bash/bash_prompt b/bash/bash_prompt new file mode 100644 index 0000000..1513f69 --- /dev/null +++ b/bash/bash_prompt @@ -0,0 +1,38 @@ +# Stripped down version of https://github.com/mathiasbynens/dotfiles/ +# Modified for my current uses / level of understanding + +# if you got xterm-256, export it! +if infocmp xterm-256color >/dev/null 2>&1; then + export TERM=xterm-256color +fi + +function parse_git_dirty() { + [[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo "*" +} + +function parse_git_branch() { + git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" +} + +# get colors from tput (else hardcode them) +if tput setaf 1 &> /dev/null; then tput sgr0 + if [[ $(tput colors) -ge 16 ]] 2>/dev/null; then + MAGENTA="\[$(tput setaf 5)\]" + ORANGE="\[$(tput setaf 11)\]" + GRAY="\[$(tput setaf 8)\]" + BLUE="\[$(tput setaf 12)\]" + BOLD="\[$(tput bold)\]" + RESET="\[$(tput sgr0)\]" + + export PS1="$BOLD$BLUE\w $RESET$GRAY\$(parse_git_branch)\n$BOLD$MAGENTA\$ $RESET" + export PS2="\[$ORANGE\]→ \[$RESET\]" + else + # TODO: write better case for too few colors... + export PS1="\w\n\$" + export PS2=">" + fi +else + # TODO: write better case for no tput... + export PS1="\w\n\$" + export PS2=">" +fi diff --git a/bash/bashrc b/bash/bashrc new file mode 100644 index 0000000..8a142b3 --- /dev/null +++ b/bash/bashrc @@ -0,0 +1,8 @@ +# if interactive shell, disable XON/XOFF to allow forward search w CTRL-S +[[ $- == *i* ]] && stty -ixon + +# Load the shell dotfiles +for file in ~/.{bash_path,bash_prompt,bash_exports,aliases}; do + [ -r "$file" ] && source "$file" +done +unset file -- libgit2 0.28.4