Skip to content

Instantly share code, notes, and snippets.

@stuartleeks
Last active July 7, 2020 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartleeks/1571893b0af83db029123435a31d58b3 to your computer and use it in GitHub Desktop.
Save stuartleeks/1571893b0af83db029123435a31d58b3 to your computer and use it in GitHub Desktop.
.bashrc-utils: Functions, aliases etc from my .bashrc
# Functions, aliases etc from my .bashrc
#
# General utils
#
# from: https://gist.github.com/stuartleeks/c21f035a411215fd20f5a85f78450d01
# simplify dlv debug etc: `dlv2 debug ./cmd/to/run arg1 arg2 ...`
dlv2() { dlv $1 $2 --headless --listen localhost:2345 --api-version 2 -- "${@:3}" ; }
#
# WSL utils
#
# wslview with path handling
wslvieww() { wslview $(wslpath -w "$1"); };
# or, to replace the original wslview:
# wslview() { command wslview $(wslpath -w "$1"); };
# openurl - pipe input to it and it launches the Windows browser for the url contained within it
openurl() { tee >( matches=($(cat /dev/stdin | grep -o 'http[s]://[0-9a-zA-Z.-\+/]*')); for line in ${matches[*]}; do wslview $line; done ); };
# Old, single-line version: openurl() { tee >(wslview $(grep -o 'http[s]://[0-9a-zA-Z.-\+/]*') ); };
# From: https://gist.github.com/stuartleeks/43111bfb76b5bc48b6e15377fbc4848e
# Set up ssh agent forwarding to host
#
# Include this in .bashrc
# Ensure that the ssh-agent service is running on windows
# build https://github.com/jstarks/npiperelay and ensure it is in your PATH (or modify the script to specify the qualified path)
# Configure ssh forwarding
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
# need `ps -ww` to get non-truncated command for matching
# use square brackets to generate a regex match for the process we want but that doesn't match the grep command running it!
ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?)
if [[ $ALREADY_RUNNING != "0" ]]; then
if [[ -S $SSH_AUTH_SOCK ]]; then
# not expecting the socket to exist as the forwarding command isn't running (http://www.tldp.org/LDP/abs/html/fto.html)
echo "removing previous socket..."
rm $SSH_AUTH_SOCK
fi
echo "Starting SSH-Agent relay..."
# setsid to force new session to keep running
# set socat to listen on $SSH_AUTH_SOCK and forward to npiperelay which then forwards to openssh-ssh-agent on windows
(setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) 2>&1 > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment