dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit ba3cde65976a29a00ded341c328b9996e1c69a86 (patch)
parent 6d0df011c8138f29b2ba73a0520d0b06e5c7db7f
Author: Alex Karle <alex@karle.co>
Date:   Mon, 13 Jan 2020 23:15:06 -0500

sh: split non-bash specific parts to POSIX sh ~/.profile

I've been toying around with OpenBSD a bit in my spare time, and it
really doesn't play nicely with all my bash fanciness (tput setaf is
broken, bash isnt installed by default, etc etc).

While I plan to keep using bash as my daily driver, I felt motivated
(similar to the vimrc refactor tonight) to split my bashrc into a POSIX
sh ~/.profile, which will be the base for all shells (ksh, zsh, bash,
etc), and the bash specific parts being in the ~/.bashrc.

This felt like a simplification while writing it. I know it doesn't look
like it, but mentally it feels good to divide the configuration into
'basic' and 'bash'.

Diffstat:
Dbash/aliases | 51---------------------------------------------------
Abash/bash_aliases | 13+++++++++++++
Mbash/bashrc | 13++++---------
Minstall.sh | 2+-
Ash/aliases | 40++++++++++++++++++++++++++++++++++++++++
Ash/profile | 32++++++++++++++++++++++++++++++++
6 files changed, 90 insertions(+), 61 deletions(-)

diff --git a/bash/aliases b/bash/aliases @@ -1,51 +0,0 @@ -#!/usr/bin/env bash - -# Detect which `ls` flavor is in use -if ls --color > /dev/null 2>&1; then # GNU `ls` - colorflag="--color" -else # macOS `ls` - colorflag="-G" -fi - -# ls aliases -alias ls='ls ${colorflag}' -alias l='ls -lAh ${colorflag}' -alias ll='ls -lh ${colorflag}' - -# Git aliases -alias ga='git add' -alias gc='git commit --verbose' -alias gd='git diff' -alias gp='git push' -alias gs='git status' -alias gst='git status' -alias gl='git pull' -alias gco='git checkout' -alias gf='git fetch' -alias glg='git log --stat --decorate' -alias glgr='git log --oneline | head -n 10' -alias g_='git stash' -alias g_p='git stash pop' -alias gb='git branch' -alias grb='git rebase' -alias grs='git reset' -alias gm='git merge' -alias vlg='vim -c "GV"' # 'vim log' of a file - -# Git completion for aliases -if [ -n "$(type -t __git_complete)" ] && [ "$(type -t __git_complete)" == "function" ]; then - __git_complete ga _git_add - __git_complete gco _git_checkout - __git_complete gd _git_diff - __git_complete gr _git_rebase - __git_complete gb _git_branch -fi - -# Quick Actions -alias v=$EDITOR -alias cddv='cd ~/.vim' -alias grep='grep --color' -alias ...='cd ../../..' -alias ....='cd ../../../..' -alias .....='cd ../../../../..' -alias rb=". ~/.bashrc" # reload bashrc diff --git a/bash/bash_aliases b/bash/bash_aliases @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Aliases specific to bash + +# Git completion for aliases +if [ -n "$(type -t __git_complete)" ] && [ "$(type -t __git_complete)" == "function" ]; then + __git_complete ga _git_add + __git_complete gco _git_checkout + __git_complete gd _git_diff + __git_complete gr _git_rebase + __git_complete gb _git_branch +fi + +alias rb='source ~/.bashrc' diff --git a/bash/bashrc b/bash/bashrc @@ -3,8 +3,7 @@ # The way I like to roll in the shell # If not running interactively, don't do anything -[ -z "$PS1" ] && return -[[ $- != *i* ]] && return # I'm paranoid... +[[ $- != *i* ]] && return # Disable XON/XOFF to allow forward search w CTRL-S stty -ixon @@ -21,11 +20,6 @@ PROMPT_COMMAND="echo; history -a" # Other Settings shopt -s checkwinsize # check win size after each cmd, update if needed -# Exports -export PATH=$HOME/bin:$PATH # Put ~/bin on the for personal scripts -export EDITOR='vi' # $EDITOR, the most important (personal) of exports -export VISUAL='vi' # Some programs give priority to this - # Custom functions function ff { find . -name "*$1*" @@ -45,8 +39,9 @@ function source_if_exists { fi } +source_if_exists "$HOME/.profile" # Common shell configuration source_if_exists "$HOME/.bash/git-completion.bash" # Git Completion -source_if_exists "$HOME/.aliases" # Aliases (source after Git Completion!) +source_if_exists "$HOME/.bash_aliases" # Bash aliases (uses git completion!) source_if_exists "$HOME/.console_theme" # Virtual Console colors (if TERM == "linux") -source_if_exists "$HOME/.bash_prompt" # Personal Prompt +source_if_exists "$HOME/.bash_prompt" # Fancy tput-colored prompt! source_if_exists "$HOME/.bashrc.local" # System specific settings diff --git a/install.sh b/install.sh @@ -35,7 +35,7 @@ for d in mutt offlineimap git nvim; do done # Traditional dotfiles -for d in bash tmux gdb X11; do +for d in bash tmux gdb X11 sh; do for f in $DOTFILES/$d/*; do try_ln $f $HOME/.`basename $f` done diff --git a/sh/aliases b/sh/aliases @@ -0,0 +1,40 @@ +#!/bin/sh +# Aliases for all shells + +# Detect which `ls` flavor is in use +if ls --color > /dev/null 2>&1; then # GNU `ls` + colorflag="--color" +elif ls -G > /dev/null 2>&1; then # macOS `ls` + colorflag="-G" +fi + +# ls aliases +alias ls='ls ${colorflag}' +alias l='ls -lAh ${colorflag}' +alias ll='ls -lh ${colorflag}' + +# Git aliases +alias ga='git add' +alias gc='git commit --verbose' +alias gd='git diff' +alias gp='git push' +alias gs='git status' +alias gst='git status' +alias gl='git pull' +alias gco='git checkout' +alias gf='git fetch' +alias glg='git log --stat --decorate' +alias glgr='git log --oneline | head -n 10' +alias g_='git stash' +alias g_p='git stash pop' +alias gb='git branch' +alias grb='git rebase' +alias grs='git reset' +alias gm='git merge' +alias vlg='vim -c "GV"' # 'vim log' of a file + +# Quick Actions +alias cddv='cd ~/.vim' +alias ...='cd ../../..' +alias ....='cd ../../../..' +alias .....='cd ../../../../..' diff --git a/sh/profile b/sh/profile @@ -0,0 +1,32 @@ +#!/bin/sh +# ~/.profile -- the sh profile +# To be used as a base for all other shell rc's +echo $PS1 +[ -z "$PS1" ] && return + +# Crucial exports +PATH=$HOME/bin:$PATH # Put ~/bin on the for personal scripts +EDITOR='vi' # $EDITOR, the most important (personal) of exports +VISUAL='vi' # Some programs give priority to this + +# Build up a somewhat fancy prompt (with SSH and error code indicators!) +if [ -n "$SSH_CLIENT" ]; then + ssh_text="[$USER@$(hostname)] " +fi + +get_error_code() { + err="$?" + if [ $err -ne "0" ]; then + echo "[$err] " + fi +} + +PS1='$(get_error_code)$PWD $SSH_PROMPT +$ ' +PS2="> " + +export PATH EDITOR VISUAL PS1 PS2 SSH_PROMPT + +if [ -e "$HOME/.aliases" ]; then + . "$HOME/.aliases" +fi