Repository navigation
Share your custom commands/modules! #1252
Replies: 145 comments 195 replies
ScreenshotCustom Command ScriptThe script below ( #!/usr/bin/zsh
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
exit 1
fi
$(git diff-files --no-ext-diff --quiet)
unstaged=$?
$(git diff-index --no-ext-diff --quiet --cached HEAD)
uncommited=$?
untracked=$(git ls-files -o --exclude-standard)
if [[ $unstaged -eq 1 || $uncommited -eq 1 || -n $untracked ]]; then
exit 0
fi
exit 1# ~/.config/starship.toml
[custom.dirty]
command = "echo '*'"
when = "git-change"
style = "fg:red"
shell = "zsh"
prefix = ""
suffix = " " |
ScreenshotCustom Command ScriptI've been bouncing between zsh and fish, so I wanted a subtle indicator to let me know which shell I was working in. I used external scripts as opposed to trying to make it work inline, since fish has its own syntax for conditional statements. # ~/.config/starship.toml
[custom.zsh]
command = "echo 🚀"
when = "~/.test_zsh.sh"
prefix = ""
[custom.fish]
command = "echo 🐟"
when = "~/.test_fish.sh"
prefix = ""~/.test_zsh.sh
#!/usr/bin/env bash
if [ "$STARSHIP_SHELL" == "zsh" ]
then
echo true
else
exit 1
fi~/.test_fish.sh
#!/usr/bin/env bash
if [ "$STARSHIP_SHELL" == "fish" ]
then
echo true
else
exit 1
fi |
ScreenshotCustom Command ScriptThis is just a visual indicator for me that my current project that I am working on does have docker/docker-compose support. The symbol will only be shown when [custom.docker]
description = "Shows the docker symbol if the current directory has Dockerfile or docker-compose.yml files"
command = "echo 🐳"
files = ["Dockerfile", "docker-compose.yml", "docker-compose.yaml"]
when = """ command -v docker &> /dev/null; exit (echo $?); """
prefix = "on "Related |
Screenshot:Custom Command ScriptThis is an alternative to the current git_status module which performs faster in some repos by calling git directly (in one of my cases: <1sec vs 4+ secs). I stole it from spaceship-prompt: https://github.com/denysdovhan/spaceship-prompt/ # ~/.config/starship.toml
format = """
...
$git_branch\
$git_commit\
$git_state\
$git_status\
${custom.git_status}\
...
"""
[git_status]
stashed = ''
# to slow
disabled=true
[custom.git_status]
description = "git status which calls git directly"
command = "~/bin/git_status_prompt.zsh || true"
when = "true"
style = "bold red"
# current master version of how to specify formats
format = "[\\[$output\\]]($style) "
#disabled = true~/bin/git_status_prompt.zsh: #!/usr/bin/zsh
# initial code from https://github.com/denysdovhan/spaceship-prompt/blob/master/sections/git_status.zsh
#
# Git status
#
# ------------------------------------------------------------------------------
# Local Config
# ------------------------------------------------------------------------------
# Don't like stashed show up, I usually always have something stashed in the main repo
SPACESHIP_GIT_STATUS_STASHED=""
# coloring happens in starship
SPACESHIP_GIT_STATUS_COLOR=""
# ------------------------------------------------------------------------------
# Utils (from https://github.com/denysdovhan/spaceship-prompt/blob/master/lib/utils.zsh)
# ------------------------------------------------------------------------------
spaceship::is_git() {
# See https://git.io/fp8Pa for related discussion
[[ $(command git rev-parse --is-inside-work-tree 2>/dev/null) == true ]]
}
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW=true}"
SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX=" ["}"
SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX="]"}"
SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED="?"}"
SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="+"}"
SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="!"}"
SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED="»"}"
SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="✘"}"
SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED="$"}"
SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED="="}"
SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="⇡"}"
SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND="⇣"}"
SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# We used to depend on OMZ git library,
# But it doesn't handle many of the status indicator combinations.
# Also, It's hard to maintain external dependency.
# See PR #147 at https://git.io/vQkkB
# See git help status to know more about status formats
spaceship_git_status() {
[[ $SPACESHIP_GIT_STATUS_SHOW == false ]] && return
spaceship::is_git || return
local INDEX git_status=""
INDEX=$(command git status --porcelain -b 2> /dev/null)
# Check for untracked files
if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status"
fi
# Check for staged files
if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
fi
# Check for modified files
if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status"
fi
# Check for renamed files
if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status"
fi
# Check for deleted files
if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
fi
# Check for stashes
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status"
fi
# Check for unmerged files
if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
fi
# Check whether branch is ahead
local is_ahead=false
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then
is_ahead=true
fi
# Check whether branch is behind
local is_behind=false
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then
is_behind=true
fi
# Check wheather branch has diverged
if [[ "$is_ahead" == true && "$is_behind" == true ]]; then
git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status"
else
[[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status"
[[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status"
fi
# changed
if [[ -n $git_status ]]; then
echo $git_status
fi
}
spaceship_git_status |
ScreenshotCustom Command ScriptShows which version of ansible is active, assuming ansible gets activated by its # ~/.config/starship.toml
[custom.ansible]
description = "Ansible version"
command = "echo -n $(ansible --version 2>/dev/null | grep ^ansible | awk '{ print $2 }') $(which ansible | sed -e s@$HOME/@@ -e s@/bin/ansible@@ -e s@/.virtual_env@@)
when = """ test -n "${ANSIBLE_HOME}" """
files = [ "ansible.cfg" ]
shell = "/bin/bash"
symbol = "Ⓐ "
format = "[$symbol$output]($style) " |
ScreenshotCustom Command ScriptShow a marker whilst the # ~/.config/starship.toml
[custom.sudo]
description = "valid sudo timestamp marker"
command = "echo -n '!'"
format = "[$symbol$output]($style) "
style = "bold fg:bright-red"
when = "sudo -vn &>/dev/null" |
ScreenshotCustom Command ScriptA custom module for displaying Deno version. Before Deno, NodeJS was the only runtime for javascript so any [custom.deno]
command = """ sed "s/deno //g" <<< "$(deno -V)" """
files = ["mod.ts", "deps.ts", "mod.js", "deps.js"]
format = "🦕 [$output](green) "
[custom.node]
command = """ sed "s/v//g" <<< "$(node -v)" """
directories = ["node_modules"]
files = ["package.json"]
format = "node [$output](green) "FAQ
|
ScreenshotCustom Command ScriptA two-fer to show SSH agent status, if you have or don't have keys available # ~/.config/starship.toml
[custom.ssh_no_keys]
description = "SSH missing keys"
when = "ssh-add -l | grep -q 'no identities'"
command = "echo 🚫"
format = "$symbol[$output]($style) "
shell = ["bash", "--noprofile", "--norc"]
symbol = "🔑"
style = "bold fg:red"
[custom.ssh_keys]
description = "SSH key count"
when = "ssh-add -l | grep -v -q 'no identities'"
command = "ssh-add -l | grep -v 'no identities' | wc -l"
format = "$symbol[$output]($style) "
shell = ["bash", "--noprofile", "--norc"]
symbol = "🔑"
style = "bold fg:green" |
|
Based off my Q&A #1880 (comment) This will fill the rest of the line with the background color of your choice. [custom.bgfill]
command = "echo a"
style="yellow bg:yellow"
when="true"
shell="sh"
format = "[$output\u001B\\[K]($style)" |
|
Hello everybody, based on a question on our Discord channel, the following displays a (pseudo) random emoji at your prompt: ScreenshotCustom Command ScriptFor a how to use the custom script, please take a look a the configuration->custom-commands section of the documentation. You can update the [custom.emoji]
description = "Displays a (pseudo) random emoji for each prompt"
# change the content of the EMOJIS array to your liking and replace the
# number 12 with the number of items in the array, minus one
command = "EMOJIS=(⛵️ 🛰 🪐 🚀 🧡 🔭 🌍 💫 ☄️ ✨ 🌠 🌌 ⭐️); EMOJI_INDEX=$(( $RANDOM % 12 + 0 )); echo ${EMOJIS[$EMOJI_INDEX]}"
# if you are on windows, replace "true" with "1"
when = "true"
shell = ["bash", "--noprofile", "--norc"]
format = "$output" |
|
zsh/bash/fish custom emoji similar to the first post, but not requiring an extra script [custom.zsh]
command = "echo 🚀"
when = """ test "$STARSHIP_SHELL" "==" "zsh" """
format = "$output"
[custom.bash]
command = "echo "
when = """ test "$STARSHIP_SHELL" "==" "bash" """
format = "$output"
[custom.fish]
command = "echo 🐟 "
when = """ test "$STARSHIP_SHELL" = "fish" """
format = "$output" |
Show remote Git serverCustom Command ScriptDisplays a Nerd Font symbol of the location of the remote git. # ~/.config/starship.toml
[custom.giturl]
# disabled = true
description = "Display symbol for remote Git server"
command = "check-git-remote"
when = 'git rev-parse --is-inside-work-tree 2> /dev/null'
shell = ["bash", "--noprofile", "--norc"]
format = "at $output "#!/usr/bin/env bash
## place in your shell path with the name 'check-git-remote'
GIT_REMOTE=$(command git ls-remote --get-url 2> /dev/null)
if [[ "$GIT_REMOTE" =~ "github" ]]; then
GIT_REMOTE_SYMBOL=" "
elif [[ "$GIT_REMOTE" =~ "gitlab" ]]; then
GIT_REMOTE_SYMBOL=" "
elif [[ "$GIT_REMOTE" =~ "bitbucket" ]]; then
GIT_REMOTE_SYMBOL=" "
elif [[ "$GIT_REMOTE" =~ "git" ]]; then
GIT_REMOTE_SYMBOL=" "
else
GIT_REMOTE_SYMBOL=" "
fi
echo "$GIT_REMOTE_SYMBOL "You need to place a |
Show system icons[custom.system_icons]
description = "Show system icons"
command = '([ $(uname -s) == "Darwin" ] && echo ) || ([ $(uname -s) == "Linux" ] && echo )'
symbol = "at"
format = "[$symbol]() [$output]($style) "
style = "bold"
shell = ["bash", "--noprofile", "--norc"]
when = "true" |
|
Shows which version of python is currently active (if different from system python), keeping things as compact as possible. # Using a custom format to highlight current non-system python in a compact manner
# - 🐍: python from virtual env is active
# - 🦎: python from pyenv is active
[custom.py]
command = """ pv=$(python --version | grep -Eo "\\d+\\.\\d+"); if [ -n "$VIRTUAL_ENV" ]; then echo "🐍 $pv"; else echo "🦎 $pv"; fi """
style = "blue"
when = """ [[ -n "$VIRTUAL_ENV" || $PATH =~ /pyenv/ ]] """
shell = ["bash", "--noprofile", "--norc"] |
|
Just some modification of @mickimnet custom Show remote git server ScreenshotCustom Command ScriptThis script just a little modification of the previous script which add the git host after the icon, I don't have enough understanding of bash scripting, so i think they are need an improvement. #!/bin/sh
# ~/.local/bin/getgithost
IFS="/"
GIT_REMOTE=$(command git ls-remote --get-url 2> /dev/null)
read -ra GIT_HOST <<< "$GIT_REMOTE"
if [[ "$GIT_REMOTE" =~ "github" ]]; then
GIT_REMOTE_SYMBOL=" "
elif [[ "$GIT_REMOTE" =~ "gitlab" ]]; then
GIT_REMOTE_SYMBOL=" "
elif [[ "$GIT_REMOTE" =~ "bitbucket" ]]; then
GIT_REMOTE_SYMBOL=" "
elif [[ "$GIT_REMOTE" =~ "git" ]]; then
GIT_REMOTE_SYMBOL=" "
else
GIT_REMOTE_SYMBOL=" localhost"
fi
echo "$GIT_REMOTE_SYMBOL${GIT_HOST[2]}"
IFS=" "The custom module declaration # ~/.config/starship/custom-module.toml
[custom.git_host]
command = 'getgithost'
when = 'git rev-parse --is-inside-work-tree 2> /dev/null'
shell = ["bash","--norc","--noprofile"]
style = "bright-yellow bold"
format = "at [$output]($style) "And then, i put it in the format = """
$username\
$hostname\
$shlvl\
$kubernetes\
${custom.dir}\
${custom.home_dir}\
$directory\
${custom.git_host}\
$git_branch\
$git_commit\
$git_state\
$git_status\
$hg_branch\
# other module
.
.
. |
|
I've been dabbling in git worktrees for the first time and it annoyed me that I couldn't tell which repo I was in anymore at a glance. There's no good icon for a git worktree, so I went with the Custom Command Script A little bit of duplication between the command and when commands, but it's so short and I didn't feel like abstracting to a separate file, so it is what it is. format = """
${custom.git_context}\
$all"""
[custom.git_context]
command = """
MAIN=$(git worktree list --porcelain 2>/dev/null | awk '/^worktree/ {print $2; exit}')
CURR=$(git rev-parse --show-toplevel 2>/dev/null)
[ -n "$MAIN" ] && [ "$MAIN" != "$CURR" ] && basename "$MAIN"
"""
format = "[$symbol$output]($style) "
shell = ["sh"]
style = "bold blue dimmed"
symbol = " "
when = """
MAIN=$(git worktree list --porcelain 2>/dev/null | awk '/^worktree/ {print $2; exit}')
CURR=$(git rev-parse --show-toplevel 2>/dev/null)
[ -n "$MAIN" ] && [ "$MAIN" != "$CURR" ]
""" |
Jujutsu (jj) tree summaryScreenshot |
|
Custom Command Script [custom.yc_linux]
command = 'cat ~/.config/yandex-cloud/config.yaml | grep current | cut -d " " -f 2'
os = 'linux'
when = true
symbol = ''
style = 'fg:color_fg0 bg:#5282FF'
format = '[ $symbol ($output )]($style)'
[custom.yc_windows]
command = '(cat ~/.config/yandex-cloud/config.yaml | Select-String "current").ToString().split(" ")[1]'
os = 'windows'
when = true
symbol = ''
style = 'fg:color_fg0 bg:#5282FF'
format = '[ $symbol ($output )]($style)' |
|
I wasn't happy with the aws module because I expect aws context to be presented on my prompt while my aws session is authenticated and active, further acknowledging any solution must not introduce any latency. I created a lightweight service for this purpose. Check it out here: https://github.com/quaintops/starship-aws-monitor
The built-in Starship
Currently supports systemd only; macOS launchd plist support can be added easily. So far tested mainly with AWS SSO and bash on Debian & Ubuntu. How It Works
Starship ConfigurationAdd this to your # Disable the built-in AWS module because it shows info even when your session is expired
[aws]
disabled = true
# Custom AWS module that reads from auth-status file
[custom.aws]
command = '''python3 -c "import json; d=json.load(open('$HOME/.aws/auth-status')); print(d.get('display','') if d.get('authenticated') else '')" 2>/dev/null'''
when = "test -f ~/.aws/auth-status"
format = " [$output]($style)"
style = "bold #FF9900"Then add format = """$hostname$directory$git_branch$git_status${custom.aws}$character""" |
|
I was unhappy with the way Go module works, it displays the locally installed Go versions, but it's not useful when working with an old Go library What is interesting is to display the Go minimal version that can be found in the [custom.gomod_version]
detect_files = ['go.mod', 'go.work']
symbol = '🐹.mod '
description = 'Display Go module version'
require_repo = true
command = '''
grep -h '^go ' go.work go.mod 2> /dev/null | sed 's/^go /v/'
'''
style = 'bold blue'This is basic, but show me interesting thing. This helps me to identify if I can use recent Go feature on a repository It looks like this for a repository where there is a go.mod file https://github.com/stretchr/testify/blob/65697cefca1d61fba40e001c90d2166be5c8df7f/go.mod#L5 that uses Go 1.17 as a minimal version
The regular Go module, would have displayed "Go 1.25.6" because it's my local version of Go |
Svn branch displayThis simple custom module will display the current svn branch the same way as the regular git_branch does (since subversion only has directories and files, tags and nested checked out folders will be treated as branches as well but this will cope properly with standard three folders layouts) The explicit shell selection is an improvement in my system since standard [custom.svn_branch]
when = "true"
command = 'svn info --no-newline --show-item relative-url "$(svn info --show-item wc-root)" 2> /dev/null | sed -e "s|^\^/||"'
shell = "bash"
description = "Current svn branch"
format = '[( $symbol $output )]($style)'
symbol = '🄪' |
budi — AI coding costs in your promptShows how much you're spending on AI coding agents (Claude Code, Cursor) today / this week / this month: [custom.budi]
command = "budi statusline --format=starship"
when = "command -v budi-daemon"
format = "[$output]($style) "
style = "cyan"
shell = ["sh"]100% local, written in Rust. https://github.com/siropkin/budi |
|
Workaround using a custom module: a script prints the branch name in green/red based on #!/usr/bin/env bash
branch=$(git branch --show-current 2>/dev/null)
[ -z "$branch" ] && exit 0
if [ -z "$(git status --porcelain 2>/dev/null)" ]; then
color="32" # green, clean
else
color="31" # red, dirty
fi
printf '\e[%sm %s\e[39m' "$color" "$branch"[git_branch]
disabled = true
[custom.git_status_colored]
command = "~/.config/starship/git_status_colored.sh"
when = "git rev-parse --is-inside-work-tree 2>/dev/null"
shell = ["bash", "--noprofile", "--norc"]
format = "[$output]($style) " |
|
I made starship-worktrunk, a small custom module for people using Worktrunk. Worktrunk’s default directory names include the branch name, which can feel redundant when your prompt already shows the branch: The command calls InstallWith Rust/Cargo installed: cargo install --git https://github.com/Faria22/starship-worktrunk --lockedConfigureReplace [custom.worktrunk]
command = "starship-worktrunk"
when = true
format = "$output "Keep your existing Compaction is best-effort and supports Worktrunk’s default Feedback welcome—especially from people with different directory configurations! |































Uh oh!
There was an error while loading. Please reload this page.
Heyo Starship Fleet 👋,
I've seen a lot of people use custom commands to make modules that fit their needs. It would be great if we could share them here for others that may want to reuse them!
Here's the template to use to share custom commands:
All reactions