Skip to content

Instantly share code, notes, and snippets.

@NickChristensen
Last active January 20, 2017 00:17
Show Gist options
  • Save NickChristensen/2dd572f67a3dc42f8f04 to your computer and use it in GitHub Desktop.
Save NickChristensen/2dd572f67a3dc42f8f04 to your computer and use it in GitHub Desktop.
A few notes and links from the Lunch & Learn
### Config, variables ###
# Use Sublime Text for all text operations (git commit, etc). See https://www.sublimetext.com/docs/2/osx_command_line.html to get the subl command
export VISUAL='subl -w';
export EDITOR='subl -w';
# Run this block if this is running over ssh
if [ -n "$SSH_CLIENT" ]; then
# Set this variable (used later) to the machine name that you logged into
sshText="\[\e[1;35m\]\h "
# Don't use Sublime Text cause it's ssh, use nano (vim blows)
export VISUAL=nano
export EDITOR=nano
fi
# Use colors in the output when applicable
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Tell node where to find global modules
export NODE_PATH=/usr/local/lib/node_modules
# $PATH is a variable that tells bash where to look for a command. If you type git, it will start at the top here and run the first command named git it can find
PATH=/Applications/MAMP/bin/php/php5.4.10/bin
PATH=$PATH:/usr/local/bin
PATH=$PATH:/usr/bin
PATH=$PATH:/bin
PATH=$PATH:/usr/sbin
PATH=$PATH:/sbin
PATH=$PATH:/usr/X11/bin
PATH=$PATH:/opt/local/bin
PATH=$PATH:/usr/local/git/bin
PATH=$PATH:/usr/local/share/npm/bin
PATH=$PATH:~/Dropbox/Sync/dotfiles/bin
### Input ###
# Makes tab completion easier and more helpful
shopt -s nocaseglob
bind 'set completion-ignore-case on'
bind 'set show-all-if-ambiguous on'
bind 'set visible-stats on'
# Load an external file (from https://github.com/git/git/tree/master/contrib/completion) for tab-completing git commands
source ~/.gitcomplete
### Handy Aliases ###
# Local IP address
alias ip='dig +short myip.opendns.com @resolver1.opendns.com'
# External IP address
alias lip='ipconfig getifaddr en0; ipconfig getifaddr en1; ipconfig getifaddr en2; ipconfig getifaddr en3; ipconfig getifaddr en4;'
# Makes navigating directories quicker
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
# Start a web server out of this folder, open it in a browser
alias serve="sleep 1 && open http://localhost:8000 & php -S localhost:8000"
# Restart the screensharing service (usually on a remote machine through ssh)
alias fixscreen='sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist && sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist'
# In file listings, use 1 column, show a / after folder names, and use colors to indicate filetypes
alias ls="ls -1F --color=auto"
# List All - Run ls, but show hidden files too
alias la='ls -A'
# List Long - Run ls, but use the long format with more info, use human readable file sizes
alias ll='ls -oh'
### Functions ###
# Check if a process is running
running(){
ps aux -c | grep -i "$1"
}
# Ask an application to quit nicely using AppleScript
quit(){
export RUNNING=`ps aux -c | grep -i "$1"`;
if [ "$RUNNING" = "" ]; then
echo 'Application not found.';
else
osascript -e "Tell Application \"$1\" to quit";
fi
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh
else
local arg=-sh
fi
if [[ -n "$@" ]]; then
du $arg -- "$@"
else
du $arg .[^.]* *
fi
}
# Tab complete your saved ssh hosts (~/.ssh/config)
ssh_load_autocomplete(){
complete -W "$(awk '/^\s*Host\s*/ { sub(/^\s*Host /, ""); print; }' ~/.ssh/config)" ssh
}
ssh_load_autocomplete
### Prompt ###
# Outputs a star (for the prompt) if there are uncommited git changes in this repo
function parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
# Outputs the current git branch (for the prompt)
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
# Other than outputting the machine name if you're in an ssh session and outputting the git info, I don't even remember what all this is. Check out https://www.google.com/search?q=customize+bash+prompt for help
PS1="${sshText}\[\e[1;34m\]\W\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" \")\[\e[1;35m\]\$(parse_git_branch) \[\e[0m\]"

The Command Line

A few notes and links from the Lunch & Learn.

Gross, why?

  • Two Sentences About Getting Older and Working on the Web - Frank Chimero

    Github is confusing, Git is confusinger, pretty much everything in a modern web stack no longer makes sense to me

  • A Baseline for Front-End Developers - Rebecca Murphey

    I wrote a README the other day for a project that I’m hoping other developers will look at and learn from, and as I was writing it, I realized that it was the sort of thing that might have intimidated the hell out of me a couple of years ago, what with its casual mentions of Node, npm, Homebrew, git, tests, and development and production builds.

    There’s a new set of baseline skills required in order to be successful as a front-end developer, and developers who don’t meet this baseline are going to start feeling more and more left behind as those who are sharing their knowledge start to assume that certain things go without saying.

Front-end relevant tools that are command line native or command line only:

.dotfiles

Several command line tools will create or use dotfiles (the filename begins with a dot) in your home folder to store preferences. In your home folder, you may find .gitignore, .gitconfig, .npmrc, .gemrc, etc. Collectively, these are called dotfiles.

Your bash preferences are stored in either .bash_profile or .bashrc (most versions of bash will read both, but I think OS X creates .bash_profile when you set up your user account so you should already have one).

A .bash_profile is just a series of shell commands, executed in order. People that get really serious about it will usually break it up into several files, then import them using the source command.

My commented .bash_profile is below, and for better examples from smarter people, check out:

Further Learning

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