Skip to content

Instantly share code, notes, and snippets.

Bruno Bronosky RichardBronosky

Block or report user

Report or block RichardBronosky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@RichardBronosky
RichardBronosky / README.md
Last active May 14, 2020
A bash plugin to manage plugins
View README.md

bash-bashplug

A bash plugin to manage plugins

Installation

Set up bash_plugins folder

(Skip this step if you already have a bash_plugins folder.)

{
# simply copy-pasta this whole block, or customize these vars and copy-pasta the rest
@RichardBronosky
RichardBronosky / README.md
Last active May 14, 2020
A bash plugin to make cd better
View README.md

bash-cdl

A bash plugin to make cd better

Installation

Set up bash_plugins folder

(Skip this step if you already have a bash_plugins folder.)

{
# simply copy-pasta this whole block, or customize these vars and copy-pasta the rest
@RichardBronosky
RichardBronosky / README.md
Last active May 14, 2020
A bash plugin to make files executable
View README.md

bash-plusx

A bash plugin to make files executable

Installation

Set up bash_plugins folder

(Skip this step if you already have a bash_plugins folder.)

{
# simply copy-pasta this whole block, or customize these vars and copy-pasta the rest
@RichardBronosky
RichardBronosky / DEMO1-handlebar_templates_via_argument.sh
Last active Mar 26, 2020
All other examples of rendering handlebars.js (double braces) templates in bash are way too complicated to put into a script
View DEMO1-handlebar_templates_via_argument.sh
#!/bin/bash
# This function works with both GNU/Linux and macOS/BSD version of sed and grep
# Inspired by https://github.com/relaxdiego/renderest
render(){
local template="$*"
for varname in $(<<<"$template" grep -oE '\{\{([A-Za-z0-9_]+)\}\}' | sed -En 's/.*\{\{([A-Za-z0-9_]+)\}\}.*/\1/p' | sort | uniq); do
template="$(<<<"$template" sed -E "s/\{\{$varname\}\}/$(sed 's_\\_\\\\\\\\_g;s_/_\\/_g' <<<"${!varname}")/g")"
done
@RichardBronosky
RichardBronosky / README.md
Created Feb 11, 2020
Pattern for using `main` and `exports` in Node.js
View README.md

Pattern for using main and exports in Node.js

Demo

~/src/node-playground(master#%)[0]
$ cat example-main_and_exports.js
#!/usr/bin/env node

const lib = require('./lib.js')
View curl-bash-env
#!/bin/bash
# curl -sL https://gist.github.com/RichardBronosky/04f3b830532ba8ba60f35b22752d88f2/raw/curl-bash-env | bash
cat <<EOF | less
# stdin_is_a_pipe
[[ -p /dev/stdin ]]; echo \$?
$([[ -p /dev/stdin ]]; echo $?)
# stdin_is_a_tty
View tput_256colors
#!/bin/bash
tput init
end=$(( $(tput colors)-1 ))
w=8
for c in $(seq 0 $end); do
tput setaf $c
[[ $c -ge $(( w*2 )) ]] && offset=2 || offset=0
[[ $(((c+offset) % (w-offset))) -eq $(((w-offset)-1)) ]] && s=$'\n'|| s=' '
View shell_script_design_goals.md

Shell Script Design Goals

  • Don't avoid bashisms unless you know bash will be unavailable
    • Use #!/bin/bash rather than #!/bin/sh
    • If you are going to try to avoid bash, you must test on a system that does not have bash
  • Always include a shebang #!
  • Handle errors
    • Use set -eu (errexit & nounset)
  • Sould be idemponent if read via source
    • Use subshells to avoid leaking unintended variables into the parent scope
View local-bin
#!/bin/bash -eu
[[ -z ${1:-} ]] && \
echo -e "\n""Usage: $0 executable_path [destination_path] ""\n" || \
executable_path="${1:-}"
: $executable_path
destination_path="${2:-/usr/local/bin}"
exec="$( basename $executable_path )"
dir="$( dirname $executable_path )"
View temp
Thu Nov 14 12:11:48 EST 2019
You can’t perform that action at this time.