Skip to content

Instantly share code, notes, and snippets.

@dekarrin
Last active December 9, 2017 15:49
Show Gist options
  • Save dekarrin/cd8d71b79b760d67755e to your computer and use it in GitHub Desktop.
Save dekarrin/cd8d71b79b760d67755e to your computer and use it in GitHub Desktop.
Bash RC
#!/bin/bash
#
# ~/.bashcolors
# Defines variables to hold shell text escape sequences
#
# remember, when using in a prompt, put escape code in between \[ and \] so
# terminal can calculate width of prompt correctly.
TEXT_reset='\e[0m'
TEXT_black='\e[0;30m'
TEXT_red='\e[0;31m'
TEXT_green='\e[0;32m'
TEXT_yellow='\e[0;33m'
TEXT_blue='\e[0;34m'
TEXT_purple='\e[0;35m'
TEXT_cyan='\e[0;36m'
TEXT_white='\e[0;37m'
TEXT_bblack='\e[1;30m'
TEXT_bred='\e[1;31m'
TEXT_bgreen='\e[1;32m'
TEXT_byellow='\e[1;33m'
TEXT_bblue='\e[1;34m'
TEXT_bpurple='\e[1;35m'
TEXT_bcyan='\e[1;36m'
TEXT_bwite='\e[1;37m'
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
. ~/.bashcolors.sh
# Add the user bin to the path
export PATH=$PATH:~/bin
alias pico=nano
alias ls='ls --color=auto'
function git-push-upstream()
{
if [ -z "$1" ]
then
echo "no upstream given, defaulting to master"
set -- master
fi
local orig_branch="$(git rev-parse --abbrev-ref HEAD)"
[ -n "$orig_branch" ] || { echo "not a git repo; exit" >&2 ; return 1 ; }
local cur_branch="$orig_branch"
git push || { echo "failed" >&2 ; return 2 ; }
while [ $# -gt 0 ]
do
local upstream="$1"
shift
git checkout "$upstream" || { echo "failed" >&2 ; return 3 ; }
git pull || { echo "failed" >&2 ; return 4 ; }
git merge "$cur_branch" || { echo "failed" >&2 ; return 5 ; }
git push || { echo "failed" >&2 ; return 6 ; }
local cur_branch="$upstream"
done
git checkout "$orig_branch" || { echo "failed" >&2 ; return 7 ; }
}
prompt_format_batpow ()
{
batpow="$(batpow.sh)"
if [[ "$batpow" = "N/A" ]]
then
echo ""
else
echo " ($batpow)"
fi
}
# Put text colors in between \[ and \] or prompt width will not be correctly
# calculated.
PS1="\[$TEXT_bgreen\]["
PS1="$PS1\[$TEXT_cyan\]\u@\h"
PS1="$PS1\[$TEXT_green\]$(prompt_format_batpow)"
PS1="$PS1\[$TEXT_green\] $(temp_get.sh)"
PS1="$PS1\[$TEXT_green\] $(date +%H:%M:%S)"
PS1="$PS1\[$TEXT_cyan\] \W"
PS1="$PS1\[$TEXT_bgreen\]]\[$TEXT_green\]\$\[$TEXT_reset\] "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment