Skip to content

Instantly share code, notes, and snippets.

View chawkinsuf's full-sized avatar

Chris Hawkins chawkinsuf

  • Tenable, Inc.
  • Jacksonville, FL
View GitHub Profile
@chawkinsuf
chawkinsuf / gist:a9dce1870fe1b5c6f885
Created December 4, 2014 19:04
Toggle visibility of hidden files in osx
alias hiddenshow='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hiddenhide='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'
@chawkinsuf
chawkinsuf / return.sh
Created September 4, 2014 18:36
Return values from bash functions
return_value()
{
local _variable_="${!1}"
local _other_="other value"
# Make a default value if the variable passed was empty
if [ -z "$_variable_" ]; then
_variable_="default"
fi
@chawkinsuf
chawkinsuf / error.sh
Created September 4, 2014 18:23
Check for errors
check_error()
{
# Check for an error
if [ "${1}" -ne "0" ]; then
# Check for a custom message
if [ ! -z "${2}" ]; then
echo "${2}"
else
echo "Fatal error"
@chawkinsuf
chawkinsuf / pipefail.sh
Created September 4, 2014 18:20
Return the proper error code if a pipe fails
# Return the proper error code if a pipe fails
set -o pipefail
@chawkinsuf
chawkinsuf / yes.sh
Created September 4, 2014 18:17
Check only the first character of a response
isyes=
read -p"Do you want to? " answer
if [[ ${answer:0:1} == 'y' || ${answer:0:1} == 'Y' ]]; then
isyes=1
fi
@chawkinsuf
chawkinsuf / options.sh
Last active August 29, 2015 14:06
Process full command line arguments
USAGE=`printf "Usage: %s [--doa] [--textoption text] text\n -a, --doa : Do A\n --textoption : Store text" $(basename $0)`
# Get inputs
aflag=""
textoption=""
while test $# -gt 0; do
case $1 in
# Normal options
--textoption)
@chawkinsuf
chawkinsuf / options.sh
Last active August 29, 2015 14:06
Process single character command line arguments
USAGE=`printf "Usage: %s [-a] text\n -a : Do A" $(basename $0)`
# Get the options
aflag=
while getopts 'a' OPTION; do
case $OPTION in
a) aflag=1
;;
?) echo "$USAGE"
exit 1
@chawkinsuf
chawkinsuf / Package Control.sublime-settings
Last active August 29, 2015 13:57
Installed Packages for Sublime Text 3
{
"installed_packages":
[
"DocBlockr",
"Generic Config",
"PackageResourceViewer",
"SideBarEnhancements",
"Sublime Bookmarks",
"SublimeCodeIntel",
"SublimeLinter",
@chawkinsuf
chawkinsuf / Preferences.sublime-settings
Last active August 29, 2015 13:56
Configuration for Sublime Text 3
{
"always_prompt_for_file_reload": true,
"auto_complete_commit_on_tab": true,
"auto_match_enabled": false,
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"copy_with_empty_selection": false,
"font_face": "Droid Sans Mono",
"font_size": 9,
"highlight_line": true,
"highlight_modified_tabs": true,
@chawkinsuf
chawkinsuf / bash.sh
Created September 17, 2013 16:19
Bash - Get an absolute path to our script directory
# Get an absolute path to our directory
basedir="$( cd "$(dirname "$0")" ; pwd -P )"