Last active
March 1, 2019 18:48
-
-
Save eoneill/7c204deca9db08fb38f284455a68e744 to your computer and use it in GitHub Desktop.
[VSCode] some helpful bash additions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will...
code
as your default$EDITOR
code
command so you can pipe stdin to it (e.g.git diff | code
)