Skip to content

Instantly share code, notes, and snippets.

@dvingo
Last active April 11, 2020 22:39
Show Gist options
  • Save dvingo/af447cae019c9ebb27df to your computer and use it in GitHub Desktop.
Save dvingo/af447cae019c9ebb27df to your computer and use it in GitHub Desktop.
Shell script to install software on mac osx.
#!/usr/bin/env bash
os=$(uname -s)
# .bashrc:
# Get the current git branch.
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
# \e[ is interpreted by the terminal emulator as an escape. same as when you enter: C-v esc
# 38;5;${i}m = tells terminal to use 256 color mode. ${i} specifies the color.
# Reference: https://misc.flogisoft.com/bash/tip_colors_and_formatting
print_colors() {
for i in {0..256}; do
printf "\e[38;5;${i}mCOLOR#${i}\e[0m\n"
done
}
#########################################################
# List most recently changed remote branches.
#########################################################
git_recent() {
for branch in $(git branch -r | grep -v HEAD); do
echo $(git show --format="%ci|%cr|%an" "$branch" | head -n1)'|'"$branch" \
| awk -F '|' '{printf "%s %s %-18s %s\n", $1, $2, $3, $4}'
done | sort -r
}
# push to every remote in the current git repo.
git_push_all() {
for remote in $(git remote); do
printf "\n\nPushing to:\n$(git remote -v | grep "$remote" | sed -n 1p)\n"
echo git push "$remote" HEAD;
git push "$remote" HEAD;
done
}
# Add and commit all files
git_do_commit () {
echo git add -A
git add -A
git status
# make a commit
if ! git diff-index --quiet HEAD; then
while read -ren 120 -p "Commit message: " msg; do
if [ -n "$msg" ]; then
echo "New commit message is :
'$msg'"
git commit -m "$msg"
break
else
printf "Enter a messaGE!!!!\n\n"
fi
done
else
echo No changes to commit.
exit
fi
git_push_all
}
##
# Dynamic dns update (used by namecheap dns).
##
function dns_update_ip {
if [ $# -ne 3 ]; then
echo "usage: "
echo "dns_update_ip <domain> <ip> <password>"
echo "see here for more info: "
echo "https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-do-i-use-a-browser-to-dynamically-update-the-hosts-ip/"
return
fi
local domain="$1"
local ip="$2"
local password="$3"
local url="https://dynamicdns.park-your-domain.com/update?host=@&domain="
local full_url="${url}${domain}&password=${password}&ip=${ip}"
curl "$full_url"
}
# Bash aliases
# git
alias ga='git add'
alias gc='git commit'
alias gcnv='git commit --no-verify'
alias gd='git diff'
alias gco='git checkout'
alias gb='git branch'
alias gp='git pull'
alias ggraph="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias gl='git log --format="%Cgreen%s %Cblue%h%Creset%n%ad -- %ar %an%n" --date="format:%A %F %T %Z"'
alias gls='git log --format="%n%Cgreen%s %Cblue%h%Creset%n%ad -- %ar %an" --date="format:%A %F %T %Z" --stat'
alias g='git status'
alias gf='git fetch'
alias gfo='git fetch -p origin'
alias grec='git_recent'
alias gr='git remote'
alias gsl='git stash list'
alias gss='git stash show'
alias gpoh='git push origin HEAD'
# "my-grep" - recursive search for term
# -r recursive
# -I - skip binary files
# -n - prefix each line of output with the 1-based line number within its input file.
alias mgrep='grep -rIn --color'
# ls
if [[ "$os" == Linux ]]; then
alias l='ls -alhF --time-style='+%F %T''
alias ll='ls -lhF --time-style='+%F %T''
alias lt='ls -lthF --time-style='+%F %T''
else if [[ "$os" == Darwin ]]; then
alias l='ls -alhGF'
alias ll='ls -lhGF'
alias lt='ls -lthGF'
fi
alias p='cd ~/projects; l'
alias httpserver='python -m http.server'
# Replicate OSX utility on GNU/Linux
# Usage: cat ~/.ssh/myKey.pub | pbcopy
function pbcopy {
xclip -selection clipboard
}
# PS1='\[\033[01;32m\]\t\[\033[00m\]:\[\033[01;34m\]\w \n\$\[\033[00m\] '
# With git branch:
PS1='\[\033[01;32m\]\d,\t\[\033[00m\]:\[\033[01;34m\]\w \[\033[01;32m\]($(git_branch))\[\033[00m\] \n\$\[\033[00m\] '
# Put this in .bash_profile on OSX, then you only need to maintain one file.
# if [ -f ~/.bashrc ]; then
# source ~/.bashrc
# fi
#--------------------
# Mac OSX specific.
#--------------------
[[ "$os" == Linux ]] && exit 1
#------------------------------------------------------
# check for xcode command line tools
#------------------------------------------------------
if [ -z `which gcc` ]; then
echo "Error: XCode command line tools not installed!"
exit 1
fi
#------------------------------------------------------
# homebrew setup
#------------------------------------------------------
if [ -z `which brew` ]; then
echo "Installing Homebrew..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
echo "Update Homebrew..."
brew update
#------------------------------------------------------
# cask setup
#------------------------------------------------------
echo "Install brew cask..."
brew tap caskroom/cask
#------------------------------------------------------
# install brew packages
#------------------------------------------------------
# dev tools
brew install vim
brew install curl
brew install autoconf
brew install automake
brew install cmake
brew install ctags
brew install colordiff
brew install git
brew install wget
brew install tree
brew install unrar
brew install potrace
brew install pidof
brew install tmux
brew install yajl
brew install ffmpeg
brew install base64
brew install dos2unix
brew install editorconfig
brew install gnu-sed
brew install nmap
# dbs / servers
# libs
brew install tbb
brew install pixman
brew install readline
brew install mcrypt
brew install imagemagick
brew install qt
brew install fontconfig
brew install freetype
brew install gettext
brew install glib
brew install graphicsmagick
brew install jpeg
brew install openjpeg
brew install libmemcached
brew install libevent
brew install libffi
brew install libpng
brew install libtiff
brew install libtool
brew install libxml2
brew install libxslt
brew install pcre
brew install reattach-to-user-namespace
# systools
brew install htop
brew install iperf
brew install ncdu
# python
brew install python
# js
brew install phantomjs
# brew install nvm
# brew install node
# java
brew cask install --force --appdir="/Applications" java
# browsers
brew cask install --force --appdir="/Applications" google-chrome
brew cask install --force --appdir="/Applications" firefox
# ides / editors
brew cask install --force --appdir="/Applications" atom
# network
brew cask install --force --appdir="/Applications" cyberduck
brew cask install --force --appdir="/Applications" iterm2
# vm / container
brew cask install --force --appdir="/Applications" vagrant
brew cask install --force --appdir="/Applications" virtualbox
brew install boot2docker
# version control
brew cask install --force --appdir="/Applications" gitx
# design
brew cask install --force --appdir="/Applications" free-ruler
# media
brew cask install --force --appdir="/Applications" vlc
brew cask install --force --appdir="/Applications" audacity
brew cask install --force --appdir="/Applications" handbrake
# infrastructure
brew cask install --force --appdir="/Applications" wireshark
# miscellaneous
brew cask install --force --appdir="/Applications" hex-fiend
brew cask install --force --appdir="/Applications" unrarx
# completions
brew tap homebrew/completions
brew install vagrant-completion
brew install bash-completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment