Skip to content

Instantly share code, notes, and snippets.

@borisschapira
Last active February 22, 2019 15:56
Show Gist options
  • Save borisschapira/b41ea13e6922d0b4792df934372ff892 to your computer and use it in GitHub Desktop.
Save borisschapira/b41ea13e6922d0b4792df934372ff892 to your computer and use it in GitHub Desktop.
Open code for workspace if available, file if configured, new workspace if nothing else
# A function to replace the `code` command
#
# With args: does what's intended.
# ```
# > code ~/.bash_history
# ```
#
# With no args, opens the first workspace it founds
# in the current folder, or a new workspace based
# on the current folder if none exists.
# ```
# > code
# ```
function code-ws() {
if [ ! $# -eq 0 ]; then
code "$@"
else
files=$(find . -maxdepth 1 -type f -name "*.code-workspace" | wc -l)
if [ $files -eq 0 ]; then
code -n .
else
code *.code-workspace
fi
fi
}
alias code=code-ws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment