dotfiles

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

commit 60aaf372279a84148dbf9ee56b97c937ab718bb5 (patch)
parent ba3cde65976a29a00ded341c328b9996e1c69a86
Author: Alex Karle <alex@karle.co>
Date:   Mon, 13 Jan 2020 23:54:09 -0500

sh: condense bash_* into bash_profile and bashrc

Also clean up ~/.bashrc and ~/.profile both, cleaning up comments,
structure, etc.

Having 5 files kinda made sense... but with the addition of the
~/.profile and ~/.aliases, it really doesn't make sense to make
~/.bash_aliases and ~/.bash_prompt ...

Diffstat:
Dbash/bash_aliases | 13-------------
Dbash/bash_prompt | 46----------------------------------------------
Mbash/bashrc | 74++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Minstall.sh | 2+-
Msh/profile | 11++++-------
5 files changed, 51 insertions(+), 95 deletions(-)

diff --git a/bash/bash_aliases b/bash/bash_aliases @@ -1,13 +0,0 @@ -#!/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/bash_prompt b/bash/bash_prompt @@ -1,46 +0,0 @@ -#!/usr/bin/env bash -# Originally inspired by https://github.com/mathiasbynens/dotfiles/ -# but since trimmed down / modified for my own purposes -if [ -n "$SSH_CLIENT" ]; then - ssh_text="[$USER@$(hostname)] " -fi - -function parse_git_dirty() { - if [ -z "$BASH_PROMPT_NO_GSTATUS" ]; then - [ "$(git status --porcelain=v1 2> /dev/null)" ] && echo "*" - fi -} - -function parse_git_branch() { - git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" -} - -function get_error_code() { - err="$?" - if [ $err -ne "0" ]; then - echo "[$err] " - fi -} - -# Preferred Prompt: Fancy with colors from tput -if tput setaf 1 &> /dev/null; then tput sgr0 - if [[ $(tput colors) -ge 8 ]] 2>/dev/null; then - SET_PREFERRED_PROMPT=1 - RED="\[$(tput setaf 1)\]" - MAGENTA="\[$(tput setaf 5)\]" - YELLOW="\[$(tput setaf 3)\]" - GRAY="\[$(tput setaf 8)\]" - BLUE="\[$(tput setaf 4)\]" - BOLD="\[$(tput bold)\]" - RESET="\[$(tput sgr0)\]" - - export PS1="$BOLD$RED\$(get_error_code)$BLUE\w $RESET$GRAY${ssh_text}\$(parse_git_branch)"$'\n'"$BOLD$MAGENTA\$ $RESET" - export PS2="$YELLOW> $RESET" - fi -fi - -# Fallback Option: No colors, No Git -if [ -z $SET_PREFERRED_PROMPT ]; then - export PS1="\w\n${ssh_text}\$ " - export PS2="> " -fi diff --git a/bash/bashrc b/bash/bashrc @@ -5,43 +5,61 @@ # If not running interactively, don't do anything [[ $- != *i* ]] && return -# Disable XON/XOFF to allow forward search w CTRL-S -stty -ixon - -# History Settings +# Settings +stty -ixon # Disable XON/XOFF to allow forward search w CTRL-S +shopt -s checkwinsize # check win size after each cmd, update if needed shopt -s histappend # append to the history file, don't overwrite it HISTSIZE=10000 # Max lines in history (in memory) HISTFILESIZE=200000 # Max size of the history file HISTIGNORE=fg:pwd:ls # Don't store common commands in history -HISTCONTROL=ignoreboth # Don't store (1) duplicate commands in history - # AND don't store lines beginning with space -PROMPT_COMMAND="echo; history -a" - -# Other Settings -shopt -s checkwinsize # check win size after each cmd, update if needed +HISTCONTROL=ignoreboth # Don't store duped / whitespace-led commands in history +PROMPT_COMMAND="echo; history -a" # Record history after each command # Custom functions -function ff { - find . -name "*$1*" -} +aw() { w3m "https://wiki.archlinux.org/index.php?search=$1"; } +ddg() { w3m "https://duckduckgo.com/lite?q=$1"; } +include() { [ -r "$1" ] && source "$1"; } -function aw { - w3m "https://wiki.archlinux.org/index.php?search=$1" -} +include "$HOME/.profile" # Common shell configuration +include "$HOME/.bash/git-completion.bash" # Git Completion +include "$HOME/.console_theme" # Virtual Console colors (if TERM == "linux") +include "$HOME/.bashrc.local" # System specific settings -function ddg { - w3m "https://duckduckgo.com/lite?q=$1" +parse_git_dirty() { + if [ -z "$BASH_PROMPT_NO_GSTATUS" ]; then + [ "$(git status --porcelain=v1 2> /dev/null)" ] && echo "*" + fi } -function source_if_exists { - if [ -r "$1" ]; then - source "$1" - fi +git_info() { + git branch --no-color 2> /dev/null | + sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" } -source_if_exists "$HOME/.profile" # Common shell configuration -source_if_exists "$HOME/.bash/git-completion.bash" # 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" # Fancy tput-colored prompt! -source_if_exists "$HOME/.bashrc.local" # System specific settings +# Preferred Prompt: fancy with colors from tput +if tput setaf 1 &> /dev/null; then + tput sgr0 # reset effects of test command + RED="\[$(tput setaf 1)\]" + MAGENTA="\[$(tput setaf 5)\]" + YELLOW="\[$(tput setaf 3)\]" + GRAY="\[$(tput setaf 8)\]" + BLUE="\[$(tput setaf 4)\]" + BOLD="\[$(tput bold)\]" + RESET="\[$(tput sgr0)\]" + + PS1_TOP="$BOLD$RED\$(last_err)$BLUE\w $RESET$GRAY$SSH_PROMPT\$(git_info)" + export PS1="$PS1_TOP\n$BOLD$MAGENTA\$ $RESET" + export PS2="$YELLOW> $RESET" +fi + +# 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/install.sh b/install.sh @@ -17,7 +17,7 @@ try_ln() { fi else # Use 'T' to prevent nesting if the dir already exists - ln -sT $1 $2 + ln -sfT $1 $2 echo "[New ] $2" | sed "s#$HOME#~#" fi } diff --git a/sh/profile b/sh/profile @@ -1,7 +1,6 @@ #!/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 @@ -11,22 +10,20 @@ 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)] " + SSH_PROMPT="[$USER@$(hostname)] " fi -get_error_code() { +last_err() { err="$?" if [ $err -ne "0" ]; then echo "[$err] " fi } -PS1='$(get_error_code)$PWD $SSH_PROMPT +PS1='$(last_err)$PWD $SSH_PROMPT $ ' PS2="> " export PATH EDITOR VISUAL PS1 PS2 SSH_PROMPT -if [ -e "$HOME/.aliases" ]; then - . "$HOME/.aliases" -fi +[ -r "$HOME/.aliases" ] && . "$HOME/.aliases"