Skip to content

Instantly share code, notes, and snippets.

View briceburg's full-sized avatar

Brice Burgess briceburg

  • toil over toil
  • albuquerque, nm
View GitHub Profile
@briceburg
briceburg / symlink-test.sh
Last active September 1, 2017 19:00
bash - detect if pwd tree contains a symlink (determine if current or parent directories are a symlink)
@briceburg
briceburg / vault.sh
Created August 24, 2017 15:25
vault wrapper example
p/help_main() {
cat <<-EOF
vault - hungry hungry AES hippo
Usage:
vault [-f|--passphrase-file <path>] [-d|--vault-dir <path>] <command>
[--] [[cubby/]entity...]
Options:
@briceburg
briceburg / .bashrc
Last active August 22, 2021 02:57
PS1 prompt with non-zero exit codes in red
# error code is in red, starting with \e[31m and ending with \e[0m escape codes.
# only non-zero exit codes appear.
export PS1='[\u@\h \W]\[\e[31m${?#0}\e[0m\]\$ '
@briceburg
briceburg / ssh_config
Created January 21, 2017 00:52
ignore strict host key checking for a specific host (e.g. github.com)
Host github.com
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
@briceburg
briceburg / example.sh
Created December 19, 2016 18:22
BASH - pattern for fetching the _resolved_ absolute path of current script [ portable ]
main(){
set -eo pipefail
local path="${BASH_SOURCE[0]}"
while [ -L "$path" ] ; do path="$(readlink "$path")" ; done
readonly CWD="$( pwd -P )"
readonly SCRIPT_CWD="$( cd $(dirname ${path}) ; pwd -P )"
# CWD is your current CWD
# SCRIPT_CWD is the resolved path of the actual script
# ^^^ works on BSD/Darwin + GNU linux
@briceburg
briceburg / local-var-test.sh
Created December 10, 2016 15:05
bash - local variable assignment not respecting command substitution exit status
#!/usr/bin/env bash
get/value(){
echo "error getting value" >&2
return 66
}
main(){
local lvar=$(get/value) || echo "local var assignment error"
var=$(get/value) || echo "global var assignment error"
@briceburg
briceburg / trap_subshell.sh
Last active November 23, 2016 04:57
errexit and bash -- conditional subshell fail
#!/usr/bin/env bash
set -e
cleanup(){
echo "I am cleanup with status $?"
}
# use trap for subshell, because;
# ( false; echo "i should not appear" ; ) || cleanup
@briceburg
briceburg / test.sh
Last active November 21, 2016 17:17
shell scripting -- [ bash ] arrays, quotes, and naked $@ tests
#!/usr/bin/env bash
# Example Usage:
# ./test.sh a "bcd" "e with \"quot'es\"." f
printf "recieved: %s \n\n" "$@"
a1=( "$@" )
a2=( $@ )
@briceburg
briceburg / prex.sh
Created November 9, 2016 20:52
prex.sh - pre extraction payloads
#!/usr/bin/env bash
# prex.sh - pre extraction payload, expects .tar.gz contents following #@TARGZ.
# usage: concatenate .tar.gz contents, and make executable:
# cat prex.sh /path/to/tar.gz > payload.sh && chmod +x payload.sh
#
# pre-extract payload
#
echo "extracting $0 ..."
@briceburg
briceburg / .gitconfig
Created September 23, 2016 00:30
.gitconfig from hell
[color]
ui = true
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green