Last active
March 10, 2025 20:12
-
-
Save furnox/8a79bba6c2cab18e2c71c47af502030a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ ! -d ~/.bashrc.d ]; then | |
mkdir ~/.bashrc.d | |
fi | |
# aliases | |
cat <<- "EOF" > ~/.bashrc.d/aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
fi | |
alias kp='ps aux | grep -i' | |
alias parrot='echo $@' | |
alias patch='patch --follow-symlinks' | |
alias df='df -h' # human-readable sizes | |
alias free='free -m' # show sizes in MB | |
# ls aliases | |
alias ls='\ls -FAh --color=always --group-directories-first --time-style=long-iso' | |
alias ll='ls -AlF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
EOF | |
# functions | |
cat <<- "EOF" > ~/.bashrc.d/_functions | |
# Utility to detect if in a git directory and what the branch is | |
# | |
__gitbranch() { | |
BRANCH=$( __git_ps1 "%s" ) | |
if [ -n "$BRANCH" ]; then | |
VER=$(__ahead_behind) | |
if [ "$BRANCH" == "()" ]; then | |
TAG=$(\git describe --tag 2>/dev/null | sed -r 's/-[0-9]+-[a-z0-9]{8}$//') | |
if [ -n "$TAG" ]; then | |
BRANCH="[Tag: **${TAG}**]" | |
else | |
BRANCH="[no branch]" | |
fi | |
else | |
BRANCH="[$BRANCH$VER]" | |
if [ -n "$(\git status -s 2>/dev/null)" ]; then | |
BRANCH=${BRANCH/]/*]} | |
fi | |
fi | |
echo "$BRANCH" | |
else | |
echo "" | |
fi | |
} | |
# | |
# Determine how many commits a git branch is ahead of and behind its remote branch | |
# | |
__ahead_behind(){ | |
EMPTY=$(git rev-list --all | wc -l) | |
if [ $EMPTY == 0 ]; then | |
echo ":-|-" | |
else | |
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) | |
ORIGIN=$(git config branch.$BRANCH.remote) | |
ORIGIN_BRANCH=$(git config branch.$BRANCH.merge | cut -d / -f 3) | |
if [[ -n $ORIGIN ]]; then | |
REMOTE="$ORIGIN/$ORIGIN_BRANCH" | |
else | |
echo "" | |
return | |
fi | |
if [[ -n $(git ls-remote --heads $ORIGIN $ORIGIN_BRANCH 2>/dev/null) ]]; then | |
echo ":$(git rev-list --left-right --count $BRANCH...$REMOTE | tr -s '\t' '|')" | |
else | |
echo "" | |
fi | |
fi | |
} | |
EOF | |
# prompt | |
cat <<- "EOF" > ~/.bashrc.d/prompt | |
PS1='\[\e[44m\]\[\e[01;36m\]$(__gitbranch)\[\e[00m\]\[\e[01;32m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]\$ ' | |
EOF | |
cat <<- "EOF" >> ~/.gitconfig | |
[alias] | |
br = branch | |
ci = commit | |
cleanx = "!f() { git reset; git co .;git clean -f; }; f" | |
co = "!f() { git checkout ${@}; if [ $? -eq 0 -a -n \"$(git branch --list -- ${@})\" ]; then git getdesc; fi; }; f" | |
diffs = "!bash -ec 'all_diff' \"$@\"" | |
ds = diff --staged | |
dump = cat-file -p | |
getdesc = "!f() { git config --local --get \"branch.`git rev-parse --abbrev-ref HEAD`.description\"; }; f" | |
setdesc = branch --edit-description | |
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short | |
loq = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative | |
lol = "!bash -ec 'loggr $0 | less -r'" | |
parent = remote show origin | |
pstash = "!bash -ec 'pystash'" | |
patch = diff --no-prefix | |
qstash = stash store $(git stash create) -m 'On $(git branch --show-current): $0' | |
st = status -sb | |
type = cat-file -t | |
up = pull | |
EOF | |
wget -O ~/.bashrc.d/git-completion https://raw.githubusercontent.com/git/git/refs/heads/master/contrib/completion/git-completion.bash | |
wget -O ~/.bashrc.d/git https://raw.githubusercontent.com/git/git/refs/heads/master/contrib/completion/git-prompt.sh | |
if [ ! -d "~/.local/bin" ]; then | |
mkdir -p ~/.local/bin | |
fi | |
wget -O ~/.local/bin/all_diff https://gist.githubusercontent.com/furnox/663efaa3633832465beac664748778d0/raw/6d40ee10457384acdd5d72c5218547bec61ce929/all_diff | |
wget -O ~/.local/bin/loggr https://gist.githubusercontent.com/furnox/098b86b19d6963b70a26a2806123133c/raw/91427bda72b42cd609fcc0f909d7c28c389c58c8/loggr | |
wget -O ~/.local/bin/pystash https://gist.githubusercontent.com/furnox/e07d714df76244bacd350622b86c3122/raw/47cc8ed0f8f223a53b865614a9feb7b009841e6c/pystash.py | |
chmod +x ~/.local/bin/all_diff ~/.local/bin/loggr ~/.local/bin/pystash | |
. ./.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment