Skip to content

Instantly share code, notes, and snippets.

@fuhoi
Last active March 16, 2019 03:50
Show Gist options
  • Save fuhoi/568b7a9742ab71a9214f085ad387e7b6 to your computer and use it in GitHub Desktop.
Save fuhoi/568b7a9742ab71a9214f085ad387e7b6 to your computer and use it in GitHub Desktop.
Git Bash for Windows
# reload: `. ~/.bashrc`
# history
HISTSIZE=10000
HISTFILESIZE=10000
# 'history -a' - append to the history file immediately
# 'history -c' - clear the current history in this session
# 'history -r' - read history into this session
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
# shortcuts
# List alias: `alias`
# Clear all: `unalias -a`
alias cgit='cd /c/git'
alias dotfiles='ls -a | grep "^\."'
alias addsshkeys='for x in `ls -d -1 ~/.ssh/* | grep -v -E ".env|.ppk|.pub|known_hosts"`; do echo "$x" && ssh-add "$x"; done; echo; ssh-add -l'
alias refreshbashrc='curl -L https://gist.github.com/adam-lincoln/568b7a9742ab71a9214f085ad387e7b6/raw/.bashrc -o ~/.bashrc && . ~/.bashrc'
# functions
# search history: `history | grep -i "path" | cut -c8-` or sh "path"
sh() { history | grep -i "$1" | cut -c8- | sort | uniq; }
# git
# [Set up an SSH key](https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html)
# [Troubleshoot SSH issues](https://confluence.atlassian.com/bitbucket/troubleshoot-ssh-issues-271943403.html)
# [Set up additional SSH keys](https://confluence.atlassian.com/bitbucket/set-up-additional-ssh-keys-271943168.html)
# [Working with SSH key passphrases](https://help.github.com/en/articles/working-with-ssh-key-passphrases)
# Create an SSH key: `ssh-keygen -f ~/.ssh/<bitbucket-username>`
# List SSH keys: `ls ~/.ssh`
# Is SSH agent running: `ps -e | grep ssh-agent`
# Start SSH agent: `eval $(ssh-agent)`
# List SSH keys: `ssh-add -l`
# Add all SSH keys: `for x in `ls -d -1 ~/.ssh/* | grep -v -E ".env|.ppk|.pub|known_hosts"`; do echo "$x" && ssh-add "$x"; done; echo; ssh-add -l`
# Add SSH key: `ssh-add ~/.ssh/<bitbucket-username>`
# Copy SSH public key: `cat ~/.ssh/<bitbucket-username>.pub | clip`
# Test SSH key: `ssh -T <bitbucket-username>@bitbucket.org`
# Git Clone: `git clone <bitbucket-username>@bitbucket.org:<repo>`
# SSH-AGENT :: START
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
# SSH-AGENT :: END
# add ssh keys
addsshkeys
# Known issues: Does not auto complete .cmd or .bat files.
# Why isn't this a default?
Escape: kill-whole-line
# Make Tab autocomplete regardless of filename case
set completion-ignore-case on
# List all matches in case multiple possible completions are possible
set show-all-if-ambiguous on
# Show extra file information when completing, like `ls -F` does
set visible-stats on
# Be more intelligent when autocompleting by also looking at the text after
# the cursor. For example, when the current line is "cd ~/src/mozil", and
# the cursor is on the "z", pressing Tab will not autocomplete it to "cd
# ~/src/mozillail", but to "cd ~/src/mozilla". (This is supported by the
# Readline used by Bash 4.)
set skip-completed-text on
# Allow UTF-8 input and output, instead of showing stuff like $'\0123\0456'
set input-meta on
set output-meta on
set convert-meta off
curl -L https://gist.github.com/adam-lincoln/568b7a9742ab71a9214f085ad387e7b6/raw/.bashrc -o ~/.bashrc && . ~/.bashrc
curl -L https://gist.github.com/adam-lincoln/568b7a9742ab71a9214f085ad387e7b6/raw/.inputrc -o ~/.inputrc && bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment