Skip to content

Commit

Permalink
Add Deno section
Browse files Browse the repository at this point in the history
Show Deno version if folder contains conventional Deno-specific files.
  • Loading branch information
vladimyr committed May 11, 2020
1 parent 50e371f commit b6c8680
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -84,6 +84,7 @@ Spaceship is a minimalistic, powerful and extremely customizable [Zsh][zsh-url]
- `` — deleted files;
- Indicator for jobs in the background (``).
- Current Node.js version, through nvm/nodenv/n (``).
- Current Deno version, through dvm (`🦕`).
- Current Ruby version, through rvm/rbenv/chruby/asdf (`💎`).
- Current Elm version (`🌳`)
- Current Elixir version, through kiex/exenv/elixir (`💧`).
Expand Down
16 changes: 16 additions & 0 deletions docs/Options.md
Expand Up @@ -257,6 +257,22 @@ If you set `SPACESHIP_NODE_DEFAULT_VERSION` to the default Node.js version and y
| `SPACESHIP_NODE_DEFAULT_VERSION` | ` ` | Node.js version to be treated as default |
| `SPACESHIP_NODE_COLOR` | `green` | Color of Node.js section |

### Deno (`deno`)

Deno section is shown only in directories that contain either `mod.ts`, `dep.ts`,
`main.ts` or `cli.ts` file.

If you set `SPACESHIP_DENO_DEFAULT_VERSION` to the default Deno version and your current version is the same as `SPACESHIP_DENO_DEFAULT_VERSION`, then Node.js section will be hidden.

| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACESHIP_DENO_SHOW` | `true` | Current Deno section |
| `SPACESHIP_DENO_PREFIX` | `$SPACESHIP_PROMPT_DEFAULT_PREFIX` | Prefix before Deno section |
| `SPACESHIP_DENO_SUFFIX` | `$SPACESHIP_PROMPT_DEFAULT_SUFFIX` | Suffix after Deno section |
| `SPACESHIP_DENO_SYMBOL` | `🦕·` | Character to be shown before Deno version |
| `SPACESHIP_DENO_DEFAULT_VERSION` | ` ` | Deno version to be treated as default |
| `SPACESHIP_DENO_COLOR` | `cyan` | Color of Deno section |

### Ruby (`ruby`)

Ruby section is shown only in directories that contain `Gemfile`, or `Rakefile`, or any other file with `.rb` extension.
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Expand Up @@ -17,6 +17,7 @@
* [Mercurial status (hg_status)](/docs/Options.md#mercurial-status-hg_status)
* [Package version (package)](/docs/Options.md#package-version-package)
* [Node (node)](/docs/Options.md#nodejs-node)
* [Deno (deno)](/docs/Options.md#deno-deno)
* [Ruby (ruby)](/docs/Options.md#ruby-ruby)
* [Elm (elm)](/docs/Options.md#elm-elm)
* [Elixir (elixir)](/docs/Options.md#elixir-elixir)
Expand Down
1 change: 1 addition & 0 deletions docs/Troubleshooting.md
Expand Up @@ -55,6 +55,7 @@ SPACESHIP_PROMPT_ORDER=(
hg # Mercurial section (hg_branch + hg_status)
# package # Package version (Disabled)
node # Node.js section
deno # Deno section
ruby # Ruby section
elixir # Elixir section
# xcode # Xcode section (Disabled)
Expand Down
46 changes: 46 additions & 0 deletions sections/deno.zsh
@@ -0,0 +1,46 @@
#
# Deno
#
# Deno is secure runtime for JavaScript and TypeScript.
# Link: https://deno.land/

# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------

SPACESHIP_DENO_SHOW="${SPACESHIP_DENO_SHOW=true}"
SPACESHIP_DENO_PREFIX="${SPACESHIP_DENO_PREFIX="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}"
SPACESHIP_DENO_SUFFIX="${SPACESHIP_DENO_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_DENO_SYMBOL="${SPACESHIP_DENO_SYMBOL="🦕 "}"
SPACESHIP_DENO_DEFAULT_VERSION="${SPACESHIP_DENO_DEFAULT_VERSION=""}"
SPACESHIP_DENO_COLOR="${SPACESHIP_DENO_COLOR="cyan"}"

# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------

# Show current version of Deno
spaceship_deno() {
[[ $SPACESHIP_DENO_SHOW == false ]] && return

# Show Deno status only for Deno-specific folders
[[ -n {mod,dep,main,cli}.ts(#qN^/) ]] || return

local 'deno_version'

if spaceship::exists dvm; then
deno_version=$(dvm current 2>/dev/null)
elif spaceship::exists deno; then
deno_version=$(deno --version 2>/dev/null | cut -d' ' -f2)
else
return
fi

[[ $deno_version == $SPACESHIP_DENO_DEFAULT_VERSION ]] && return

spaceship::section \
"$SPACESHIP_DENO_COLOR" \
"$SPACESHIP_DENO_PREFIX" \
"${SPACESHIP_DENO_SYMBOL}${deno_version}" \
"$SPACESHIP_DENO_SUFFIX"
}
1 change: 1 addition & 0 deletions spaceship.zsh
Expand Up @@ -48,6 +48,7 @@ if [ -z "$SPACESHIP_PROMPT_ORDER" ]; then
hg # Mercurial section (hg_branch + hg_status)
package # Package version
node # Node.js section
deno # Deno section
ruby # Ruby section
elm # Elm section
elixir # Elixir section
Expand Down

0 comments on commit b6c8680

Please sign in to comment.