Skip to content

Instantly share code, notes, and snippets.

@eoneill
Last active March 1, 2019 18:48
Show Gist options
  • Save eoneill/7c204deca9db08fb38f284455a68e744 to your computer and use it in GitHub Desktop.
Save eoneill/7c204deca9db08fb38f284455a68e744 to your computer and use it in GitHub Desktop.
[VSCode] some helpful bash additions
# if we have vscode installed...
if hash code 2>/dev/null; then
# VSCode as default editor
export EDITOR="code -w"
# VSCode command line currently does not support piping from stdin
# This helper function wraps the `code` command to capture piped stdin
function code() {
# reference to the original `code` command
local code=$(which code)
# if incoming stdin via a pipe...
if [[ -p /dev/stdin ]] ; then
local tmpFile=$(mktemp -t stdin)
tee "$tmpFile" > /dev/null
$code "$@" "$tmpFile"
else
# otherwise, pass along any arguments to the original `code`
$code "$@"
fi
}
fi
@eoneill
Copy link
Author

eoneill commented Jun 6, 2017

This will...

  • set code as your default $EDITOR
  • wrap the code command so you can pipe stdin to it (e.g. git diff | code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment