Last active
February 28, 2018 23:37
-
-
Save ramonchito2/2c6b9e838466e31f53630223ae6228f5 to your computer and use it in GitHub Desktop.
Helpful bash aliases and functions for .bashrc. -- Includes function to easily navigate to a specified folder with <tab> auto completion
This file contains 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
##### NOTE - The following aliases and functions use my Cygwin directory. Be sure to edit these for your use case. #### | |
# Override source alias to default to this file | |
alias source='source /home/jglynn/.bashrc' | |
# Override 'ls' command | |
alias ls='ls -AhF --color=tty' #classify files in colour by default | |
alias ll='ls -lhA' #long list | |
# Demo - quick ssh into sites | |
# - the following uses the domain 'site' which is mapped to a server's ip in the host file | |
# -- this domain shortcut also used in commands such as rsync (rsync -va root@site:/.) | |
alias sshfl='ssh root@site' | |
# This allows Cygwin Window to have the correct Tab Names | |
PROMPT_COMMAND='ConEmuC -StoreCWD' | |
# Enable pbcopy / pbpaste in Cygwin | |
# - e.g. pbcopy ~/.ssh/id_rsa.pub | |
alias pbcopy="cat >/dev/clipboard" | |
alias pbpaste="cat /dev/clipboard" | |
# Quicker npm project build commands | |
alias build="npm run dev" | |
alias watch="npm run watch" | |
######### FUNCTIONS ########## | |
# This is one of my favorite functions. Allows blazing fast navigation into a directory of your choosing. | |
# I use this specifically to quickly access all of my project folders | |
# - (requires bash completion to be installed) | |
# Directory of your choosing | |
home_dir='/cygdrive/c/Users/jglynn/webDev' | |
# Custom auto complete for home function | |
_home () { | |
local cur hdir | |
COMPREPLY=() | |
cur=${COMP_WORDS[COMP_CWORD]} | |
k=0 | |
hdir=${home_dir} | |
i=${hdir} # the directory from where to start | |
for j in $( compgen -f "$i/$cur" ); do # loop trough the possible completions | |
[ -d "$j" ] && j="${j}/" || j="${j} " # if its a dir add a slash, else a space | |
COMPREPLY[k++]=${j#$i/} # remove the directory prefix from the array | |
done | |
return 0 | |
} | |
# Navigates to "directory of your choosing". | |
# - When paired with _home function, allows the parameter to be <tab> completed | |
# -- e.g. If there is a 'files' folder in the 'home_dir', typing 'home fi<tab>' will autocomplete to 'home files/' | |
# -- ... and so on. Pressing enter will automatically navigate to that folder. | |
function home() { | |
local new_dir | |
new_dir=${home_dir} | |
if [[ $1 ]]; then | |
new_dir=${new_dir}/$@; | |
fi | |
cd ${new_dir} | |
} | |
# Enables <tab> completion on the 'home' function using _home | |
complete -o nospace -F _home home | |
# Windows - executing the following function opens your hosts file in notepad with admin priviledges | |
function edithosts() { | |
( notepad /cygdrive/c/Windows/System32/drivers/etc/hosts ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment