I hereby claim:
- I am mattolenik on github.
- I am matthewolenik (https://keybase.io/matthewolenik) on keybase.
- I have a public key ASCQ3fh9LGPK1UYNYp6L_TGzifcHtI_bVCLZHJyIM-Vk-Qo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| gem_dir = "#{Dir.home}/.vagrant.d/gems/#{RUBY_VERSION}" | |
| begin | |
| name = "inifile" | |
| version = "3.0.0" | |
| Gem::Specification.find_by_name(name, version) | |
| rescue Gem::LoadError | |
| require "rubygems/dependency_installer" | |
| installer = Gem::DependencyInstaller.new(:document => [], :install_dir => gem_dir) | |
| installer.install(name, version) |
| # Install any missing plugins upon 'vagrant up' | |
| def ensure_plugins(required_plugins) | |
| if ARGV[0] == 'up' | |
| missing_plugins = required_plugins.select {|p| not Vagrant.has_plugin? p} | |
| unless missing_plugins.empty? | |
| plugins = missing_plugins.join(' ') | |
| puts "Found missing plugins: #{plugins}, installing..." | |
| exec "vagrant plugin install #{plugins} && vagrant up" | |
| end | |
| end |
| # Caveat: grep can't match the beginning of the file, so this will catch files with a shebang on any line, | |
| # such as a script being embedded in another kind of file. To get around this each file should be checked with head -n1 | |
| grep -Ir '^#!/.*sh' --exclude-dir 'node_modules' --exclude '*.tpl' ./* | awk -F: '{print $1}' |
| [[ 'function some_func ( ) {' =~ ^[[:blank:]]*(function[[:blank:]]+)?([\x30-\x39\x41-\x5A\x61-\x7A\xA0-\x19FF\+\-\.\^\/\?,%#_@:~]+)[[:blank:]]*\([[:blank:]]*\)[[:blank:]]*({)?$ ]] | |
| #BASH_REMATCH results: | |
| #0 - whole match | |
| #1 - either 'function' or empty string | |
| #2 - function name | |
| #3 - either '{' or empty string | |
| #Character ranges include pretty much all unicode and normal characters that bash will accept. |
| # Strips n characters from the beginning of the line. This example uncomments a line in /etc/sudoers. | |
| n=3 | |
| cat /etc/sudoers | awk '/^# %wheel ALL=\(ALL\) ALL/ {$0=substr($0,$n)} 1 |
| #!/bin/bash | |
| # From https://stackoverflow.com/questions/16115144/bash-save-and-restore-trap-state-easy-way-to-manage-multiple-handlers-for-trap | |
| trap_stack_name() { | |
| local sig=${1//[^a-zA-Z0-9]/_} | |
| echo "__trap_stack_$sig" | |
| } | |
| extract_trap() { | |
| echo ${@:3:$(($#-3))} | |
| } |
| # From https://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal | |
| # note: printf is used instead of echo to avoid backslash | |
| # processing and to properly handle values that begin with a '-'. | |
| log() { printf '%s\n' "$*"; } | |
| error() { log "ERROR: $*" >&2; } | |
| fatal() { error "$@"; exit 1; } | |
| # appends a command to a trap | |
| # |
| # Searches for a named argument in the form of "key=value". | |
| # Returns the value associated with the key. | |
| # | |
| get_named_arg() { | |
| local key="$1" | |
| local default="${2:-}" | |
| shift 2 | |
| for pair in "$@"; do | |
| if [[ $pair =~ ^([^=]+)=([^=]*)$ ]] && [[ ${BASH_REMATCH[1]} == "$key" ]]; then | |
| printf %s "${BASH_REMATCH[2]}" |
| # Creates/joins a shared session using session groups (-t option). | |
| # This simplifies making a shared group. Just invoke tmuxx from anywhere | |
| # and it'll always join to the same, shared session. | |
| # | |
| # Parameters: | |
| # $1 the name of the session group, defaults to 'main' | |
| tmuxx () { | |
| local session="${1:-main}" | |
| tmux new-session -t "$session" | |
| } |