Skip to content

Instantly share code, notes, and snippets.

@andkirby
Last active August 17, 2020 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andkirby/0e2982bee321aa611bc66385dee5f399 to your computer and use it in GitHub Desktop.
Save andkirby/0e2982bee321aa611bc66385dee5f399 to your computer and use it in GitHub Desktop.
Install .bashrc init code
#!/usr/bin/env bash
###################################
# Init content for .bashrc file
#
# curl -Ls https://gist.github.com/andkirby/0e2982bee321aa611bc66385dee5f399/raw/bashrc_init_install.sh | bash
# curl -Ls https://bit.ly/bash-init | bash
###################################
touch ~/.bashrc
if cat ~/.bashrc | grep '# Init .bashrc content' > /dev/null; then
echo "notice: You have updated .bashrc file." > /dev/stderr
exit 4
fi
echo >> ~/.bashrc
curl -Ls https://gist.github.com/andkirby/0e2982bee321aa611bc66385dee5f399/raw/bashrc_z_base >> ~/.bashrc
echo >> ~/.bashrc
curl -Ls https://gist.github.com/andkirby/0e2982bee321aa611bc66385dee5f399/raw/bashrc_z_git >> ~/.bashrc
echo >> ~/.bashrc
curl -Ls https://gist.github.com/andkirby/0e2982bee321aa611bc66385dee5f399/raw/bashrc_z_default_dir >> ~/.bashrc
echo >> ~/.bashrc
echo 'Added initial ~/.bashrc content.'
echo 'Source: https://gist.github.com/andkirby/0e2982bee321aa611bc66385dee5f399'
echo 'Please run the command to get updates:'
echo ' $ . ~/.bashrc'
# >>> Init .bashrc content
export SHELL=bash
export LS_OPTIONS='--color=auto'
# in some OS `dircolors` doesn't exist
eval "`dircolors 2> /dev/null || true`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -lA'
alias l='ls $LS_OPTIONS -la'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
export TERM=xterm
export EDITOR=nano
# edit .bashrc file
alias bsh="${EDITOR} ~/.bashrc && source ~/.bashrc"
# <<<
# == Use chanaged/default directory on load
DEFAULT_DIR=/d/home
# go to default directory
alias gh='cd '${DEFAULT_DIR}
# remember changed directory
cd() { builtin cd ${@} && keep_last_dir; }
keep_last_dir() { pwd > ~/.bashrc.last_dir; }
if [ -z "${BASHRC_INIT}" ]; then
export BASHRC_INIT=1
readonly BASHRC_INIT
change_dir=${DEFAULT_DIR}
if [[ -f ~/.bashrc.last_dir ]]; then
change_dir=$(cat ~/.bashrc.last_dir)
fi
# go to default directory
[ -d ${change_dir} ] && cd ${change_dir}
fi
# <<<
# == GIT shortcuts
alias gg='git status'
alias gl='git log -3'
alias glast='git reset --soft HEAD^'
alias gc='git add $(git diff --name-only --cached) && git commit -m'
alias ga='git add -u'
alias gd='git diff --cached'
alias gp='git push'
alias gpt='git push && git push --tags'
# <<<
@andkirby
Copy link
Author

andkirby commented Nov 2, 2016

curl -Ls https://gist.github.com/andkirby/0e2982bee321aa611bc66385dee5f399/raw/bashrc_init_install.sh | bash

@andkirby
Copy link
Author

andkirby commented Jul 13, 2017

Short URL:

curl -Ls https://bit.ly/bash-init | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment