Improve bash config
This commit is contained in:
parent
d6103b4c25
commit
6211a84324
86
bash/aliases
Normal file
86
bash/aliases
Normal file
|
@ -0,0 +1,86 @@
|
|||
|
||||
alias q='exit'
|
||||
alias clr='clear'
|
||||
alias catn='cat -n' # cat + line numbers
|
||||
|
||||
alias -- -="cd -"
|
||||
|
||||
# Command fixes
|
||||
alias ln="${aliases[ln]:-ln} -v" # verbose ln
|
||||
alias wget='wget -c' # Resume download if possible
|
||||
alias rename='noglob rename'
|
||||
|
||||
# Shortcut for git
|
||||
g() {
|
||||
if [[ $# -gt 0 ]]; then
|
||||
${aliases[git]:-git} $@
|
||||
else
|
||||
${aliases[git]:-git} status --short
|
||||
fi
|
||||
}
|
||||
|
||||
alias git='hub'
|
||||
alias gi='git init'
|
||||
alias ga='git add'
|
||||
alias gap='git add --patch'
|
||||
alias gc='git commit --verbose'
|
||||
alias gcm='git commit --verbose -m'
|
||||
alias gco='git checkout'
|
||||
alias gcl='git clone'
|
||||
alias gp='git push'
|
||||
alias gpl='git pull'
|
||||
alias gb='git branch'
|
||||
alias gt='git tag'
|
||||
alias gs='git status'
|
||||
alias gr='git reset "HEAD^"'
|
||||
alias gd='git diff'
|
||||
|
||||
if is-callable 'tmux'; then
|
||||
alias t='tmux new -s x || tmux attach -t x'
|
||||
alias tl='tmux list-sessions'
|
||||
alias ts='tmux switch'
|
||||
|
||||
tmux-send() {
|
||||
tmux send-keys -s "x" $1 Enter
|
||||
}
|
||||
fi
|
||||
|
||||
# OS-specific aliases
|
||||
if [[ "$OSTYPE" == darwin* ]]; then
|
||||
alias codekit='open -a CodeKit'
|
||||
alias b='brew'
|
||||
alias v='vim'
|
||||
alias e="emacsclient -n" # Emacs server must be running!
|
||||
else
|
||||
alias ipt='sudo iptables'
|
||||
fi
|
||||
|
||||
# transmission-remote
|
||||
if is-callable 'transmission-remote'; then
|
||||
alias bt="transmission-remote server"
|
||||
alias btl="bt -l"
|
||||
fi
|
||||
|
||||
alias va='vagrant'
|
||||
alias rk='rake'
|
||||
alias rkg='rake -g'
|
||||
|
||||
# Interpreters
|
||||
alias rb='ruby'
|
||||
alias rbe='rbenv'
|
||||
alias be='bundle exec'
|
||||
alias spec='rspec'
|
||||
|
||||
alias py='python'
|
||||
alias pye='pyenv'
|
||||
[ -e /Applications/love.app ] && alias love="/Applications/love.app/Contents/MacOS/love"
|
||||
|
||||
# Bash-only aliases
|
||||
if [ -z "$ZSH_VERSION" ]; then
|
||||
# Allow aliases to be with sudo
|
||||
alias sudo='sudo '
|
||||
|
||||
alias ls='ls -G'
|
||||
alias l="ls -o"
|
||||
alias la="ls -AGFoh"
|
||||
fi
|
36
bash/config
Normal file
36
bash/config
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Case-insensitive globbing (used in pathname expansion)
|
||||
shopt -s nocaseglob
|
||||
# Append to the Bash history file, rather than overwriting it
|
||||
shopt -s histappend
|
||||
# Autocorrect typos in path names when using `cd`
|
||||
shopt -s cdspell
|
||||
# Check the window size after each command and, if necessary, update the values
|
||||
# of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
||||
# Enable bash 4 options
|
||||
shopt -s autocd 2>/dev/null
|
||||
shopt -s globstar 2>/dev/null
|
||||
|
||||
|
||||
#### Completion #############################################
|
||||
|
||||
# Add tab completion for many Bash commands
|
||||
if is-callable "brew" && [ -f "$(brew --prefix)/etc/bash_completion" ]; then
|
||||
source "$(brew --prefix)/etc/bash_completion";
|
||||
elif [ -f /etc/bash_completion ]; then
|
||||
source /etc/bash_completion;
|
||||
fi
|
||||
|
||||
# Enable tab completion for `g` by marking it as an alias for `git`
|
||||
if type _git &> /dev/null && [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
|
||||
complete -o default -o nospace -F _git g;
|
||||
fi
|
||||
|
||||
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
|
||||
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2 | tr ' ' '\n')" scp sftp ssh;
|
||||
|
||||
# Add `killall` tab completion for common apps
|
||||
complete -o "nospace" -W "Contacts Calendar Dock Finder Mail Safari iTunes SystemUIServer Terminal Tweetbot" killall
|
35
bash/path
Normal file
35
bash/path
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
declare -a paths_prepend=(
|
||||
"/usr/local/bin"
|
||||
"/usr/local/sbin"
|
||||
"$HOME/.dotfiles/bin"
|
||||
"$HOME/.rbenv/shims"
|
||||
"$HOME/.pyenv/shims"
|
||||
"$HOME/.rbenv/bin"
|
||||
"$HOME/.pyenv/bin"
|
||||
"$(brew --prefix coreutils)/libexec/gnubin"
|
||||
)
|
||||
|
||||
declare -a paths_append=(
|
||||
# ...
|
||||
)
|
||||
|
||||
# Prepend directories to PATH
|
||||
for index in ${!dirs_to_prepend[*]}; do
|
||||
if [ -d ${dirs_to_prepend[$index]} ]; then
|
||||
# If these directories exist, then prepend them to existing PATH
|
||||
PATH="${dirs_to_prepend[$index]}:$PATH"
|
||||
fi
|
||||
done
|
||||
|
||||
# Append directories to PATH
|
||||
for index in ${!dirs_to_append[*]}; do
|
||||
if [ -d ${dirs_to_append[$index]} ]; then
|
||||
# If these bins exist, then append them to existing PATH
|
||||
PATH="$PATH:${dirs_to_append[$index]}"
|
||||
fi
|
||||
done
|
||||
|
||||
unset paths_prepend paths_append
|
||||
export PATH
|
136
bash/prompt
Normal file
136
bash/prompt
Normal file
|
@ -0,0 +1,136 @@
|
|||
#!/bin/bash
|
||||
|
||||
# inspired from: https://raw.githubusercontent.com/necolas/dotfiles/master/shell/bash_prompt
|
||||
|
||||
prompt_git() {
|
||||
local s=""
|
||||
local branchName=""
|
||||
|
||||
# check if the current directory is in a git repository
|
||||
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; printf "%s" $?) == 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 index is up to date
|
||||
git update-index --really-refresh -q &>/dev/null
|
||||
|
||||
# check for uncommitted changes in the index
|
||||
if ! $(git diff --quiet --ignore-submodules --cached); then
|
||||
s="$s+";
|
||||
fi
|
||||
|
||||
# check for unstaged changes
|
||||
if ! $(git diff-files --quiet --ignore-submodules --); then
|
||||
s="$s!";
|
||||
fi
|
||||
|
||||
# check for untracked files
|
||||
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
|
||||
s="$s?";
|
||||
fi
|
||||
|
||||
# check for stashed files
|
||||
if $(git rev-parse --verify refs/stash &>/dev/null); then
|
||||
s="$s$";
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# get the short symbolic ref
|
||||
# if HEAD isn't a symbolic ref, get the short SHA
|
||||
# otherwise, just give up
|
||||
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
|
||||
git rev-parse --short HEAD 2> /dev/null || \
|
||||
printf "(unknown)")"
|
||||
|
||||
[ -n "$s" ] && s=" [$s]"
|
||||
|
||||
printf "%s" "$1$branchName$s"
|
||||
else
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
set_prompts() {
|
||||
local black=""
|
||||
local blue=""
|
||||
local bold=""
|
||||
local cyan=""
|
||||
local green=""
|
||||
local orange=""
|
||||
local purple=""
|
||||
local red=""
|
||||
local reset=""
|
||||
local white=""
|
||||
local yellow=""
|
||||
|
||||
local hostStyle=""
|
||||
local userStyle=""
|
||||
|
||||
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
|
||||
tput sgr0 # reset colors
|
||||
|
||||
bold=$(tput bold)
|
||||
reset=$(tput sgr0)
|
||||
|
||||
# Solarized colors
|
||||
# (https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized#the-values)
|
||||
black=$(tput setaf 0)
|
||||
blue=$(tput setaf 33)
|
||||
cyan=$(tput setaf 37)
|
||||
green=$(tput setaf 64)
|
||||
orange=$(tput setaf 166)
|
||||
purple=$(tput setaf 125)
|
||||
red=$(tput setaf 124)
|
||||
white=$(tput setaf 15)
|
||||
yellow=$(tput setaf 136)
|
||||
else
|
||||
bold=""
|
||||
reset="\e[0m"
|
||||
|
||||
black="\e[1;30m"
|
||||
blue="\e[1;34m"
|
||||
cyan="\e[1;36m"
|
||||
green="\e[1;32m"
|
||||
orange="\e[1;33m"
|
||||
purple="\e[1;35m"
|
||||
red="\e[1;31m"
|
||||
white="\e[1;37m"
|
||||
yellow="\e[1;33m"
|
||||
fi
|
||||
|
||||
# build the prompt
|
||||
|
||||
# logged in as root
|
||||
if [[ "$USER" == "root" ]]; then
|
||||
userStyle="\[$bold$red\]"
|
||||
else
|
||||
userStyle="\[$orange\]"
|
||||
fi
|
||||
|
||||
# connected via ssh
|
||||
if [[ "$SSH_TTY" ]]; then
|
||||
hostStyle="\[$bold$red\]"
|
||||
else
|
||||
hostStyle="\[$yellow\]"
|
||||
fi
|
||||
|
||||
# set the terminal title to the current working directory
|
||||
PS1="\[\033]0;\w\007\]"
|
||||
|
||||
PS1+="\n" # newline
|
||||
PS1+="\[$userStyle\]\u" # username
|
||||
PS1+="\[$reset$white\]@"
|
||||
PS1+="\[$hostStyle\]\h" # host
|
||||
PS1+="\[$reset$white\]: "
|
||||
PS1+="\[$green\]\w" # working directory
|
||||
PS1+="\$(prompt_git \"$white on $cyan\")" # git repository details
|
||||
PS1+="\n"
|
||||
PS1+="\[$reset$white\]\$ \[$reset\]" # $ (and reset color)
|
||||
|
||||
export PS1
|
||||
}
|
||||
|
||||
set_prompts
|
||||
unset set_prompts
|
18
bash_profile
Normal file
18
bash_profile
Normal file
|
@ -0,0 +1,18 @@
|
|||
function is-callable {
|
||||
which "$1" > /dev/null
|
||||
}
|
||||
|
||||
# set 256 color profile where possible
|
||||
if [[ $COLORTERM == gnome-* && $TERM == xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
|
||||
export TERM=gnome-256color
|
||||
elif infocmp xterm-256color >/dev/null 2>&1; then
|
||||
export TERM=xterm-256color
|
||||
fi
|
||||
|
||||
|
||||
#### Other Settings #########################################
|
||||
|
||||
source ~/.bash/path
|
||||
source ~/.bash/aliases
|
||||
source ~/.bash/config
|
||||
source ~/.bash/prompt
|
4
bashrc
4
bashrc
|
@ -1,3 +1 @@
|
|||
# Source component rcfiles
|
||||
# source ~/.zsh/functions
|
||||
# source ~/.zsh/aliases
|
||||
[ -n "$PS1" ] && source ~/.bash_profile;
|
||||
|
|
24
curlrc
Normal file
24
curlrc
Normal file
|
@ -0,0 +1,24 @@
|
|||
# cURL default configuration file
|
||||
# http://curl.haxx.se/docs/manpage.html
|
||||
|
||||
# Limit the time (in seconds) the connection to the server is allowed to take
|
||||
connect-timeout = 30
|
||||
|
||||
# Follow HTTP redirects
|
||||
location
|
||||
|
||||
# Limit the time (in seconds) the whole operation is allowed to take
|
||||
# (prevents cURL from hanging due to slow networks or links going down)
|
||||
max-time = 300
|
||||
|
||||
# When following a redirect, automatically set the previous URL as referer
|
||||
referer = ";auto"
|
||||
|
||||
# Show error messages
|
||||
show-error
|
||||
|
||||
# Do not show the progress meter
|
||||
silent
|
||||
|
||||
# Send a fake UA string for the HTTP servers that sniff it
|
||||
user-agent = "Mozilla/5.0 Gecko"
|
19
inputrc
Normal file
19
inputrc
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
# inputrc
|
||||
|
||||
# Use case-insensitive TAB autocompletion
|
||||
set completion-ignore-case on
|
||||
|
||||
# Auto list tab completions (use instead of TAB-cycling)
|
||||
set show-all-if-ambiguous on
|
||||
|
||||
# Make TAB cycle through possible completions
|
||||
# "\t": menu-complete
|
||||
# Make SHIFT-TAB reverse cycle through possible completions
|
||||
# "\e[Z": "\e-1\C-i"
|
||||
|
||||
# Use the string that has already been typed as the prefix for searching
|
||||
# through commands (i.e. more intelligent Up/Down-arrow behavior)
|
||||
"\e[B": history-search-forward
|
||||
"\e[A": history-search-backward
|
Loading…
Reference in a new issue