Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Wrapper over docker-compose to run on remote server.
# Usage:
# Takes same arguments as docker-compose.
# Typical usage:
# remote-compose server down
@mikeslattery
mikeslattery / .bashrc
Created March 6, 2019 16:36 — forked from JanTvrdik/.bashrc
ssh-agent support for Git Bash / MinGW / msys / Windows
# put this in ~/.bashrc
export SSH_AUTH_SOCK=/tmp/.ssh-socket
ssh-add -l > /dev/null
if [ $? = 2 ]; then
rm -f $SSH_AUTH_SOCK
echo Starting new ssh-agent...
eval $(ssh-agent -a $SSH_AUTH_SOCK) > /dev/null
ssh-add && echo "ssh-agent set up successfully with the following keys:" && ssh-add -l
fi
@mikeslattery
mikeslattery / template.sh
Last active May 15, 2019 21:44
Template engine for Bash
#!/bin/bash
# Interpolates variables in a text file
# $1 = template filename
templatefile="$1"
shift
eval "$(echo -e "cat <<HEREX\n$(cat "$templatefile")\nHEREX\n")"
#!/bin/bash
# More seemless integration between git-bash/WSL/Cygwin and Docker for Windows
set -euo pipefail
( [ -d 'C:\'] && cygpath . > /dev/null; ) || \
{ echo 'Must be run from GitBash, Msys or Cygwin'; exit 1; }
export MSYS_NO_PATHCONV=1
USER="$(whoami)"
docker run \
@mikeslattery
mikeslattery / template.inc.sh
Last active October 28, 2019 20:31
An empty Bash script as a template. See #TODO for places to change.
#!/bin/bash
usage() { sed 's/^ //' >&2 <<<USAGETEXT
#TODO: Description of script here.
Usage:
$(sed -r 's/^#@@ (.*)$/ \1/p' < "${BASH_SOURCE[0]}")
Variables:
$(sed -r 's/^#@# (.*)$/ \1/p' < "${BASH_SOURCE[0]}")
USAGETEXT
@mikeslattery
mikeslattery / shlint.sh
Created January 23, 2020 16:06
Lint shell scripts
#!/bin/bash
# Thorough syntax check for #!/bin/sh scripts.
# (For bash scripts, shellcheck by itself is enough)
set -eu
for f in "$@"; do
dash -n "$f" && \
shellcheck -x "$f" && \
@mikeslattery
mikeslattery / notify-send.ps1
Last active February 20, 2020 18:02
Windows Notification Toast
function notify($notificationTitle) {
$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[void][Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
# Fetch empty template
$templateType = [Windows.UI.Notifications.ToastTemplateType]::ToastText01
$template = [xml]([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($templateType).getXml())
#Convert to .NET type for XML manipuration
[void]$template.GetElementsByTagName("text").AppendChild($template.CreateTextNode($notificationTitle))
@mikeslattery
mikeslattery / alpine-chroot.sh
Created April 30, 2020 15:37
Create a temporary Alpine chroo
#!/bin/sh
# Create and launch an alpine chroot
# If /tmp is not tmpfs, change this to /dev/shm
rootfs=/tmp/alpine
set -eu
if ! [ -f $rootfs/etc/resolv.conf ]; then
if ! [ -f ~/Downloads/alpine.tar.gz ]; then
curl -Lf -o ~/Downloads/alpine.tar.gz http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-minirootfs-3.11.6-x86_64.tar.gz
@mikeslattery
mikeslattery / init.gradle
Last active May 1, 2020 19:17
Build gradle projects to RAM
// This goes in ~/.gradle/init.d/tmpfs.gradle
def ramdir='/tmp/gradle'
gradle.projectsLoaded {
rootProject.allprojects {
buildDir = "${ramdir}${project.path}/build"
//println "${project.name}.buildDir = ${buildDir}"
}
#!/bin/bash
# Workaround docker wrapper for git-bash/Msys/Cygwin quirks
# Copy this to ~/bin/docker or /usr/local/bin/docker
set -euo pipefail
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL='*'
os="$(uname -o)"