mimirFast and minimal shell prompt

联合创作 · 2023-09-30 03:43

Archived project. No maintenance.


What does this mean? No further code will be committed and the repository will remain in a read-only state. Releases will still be available for download.


Current status: Mímir is stable (as far as I know).


Why? I no longer use Mímir personally, I've switched to using Starship.


Mímir


GitHub Release Build Status Go Report Card Software License


Mímir is a fast and minimal shell prompt written in Go. The look of Mímir is inspired by Pure and the functionality is inspired by prettyprompt.



The Mímir Go binary only displays the (pre) prompt line with all the information. The actual prompt line used for input is configured in the shell's config file. This allows for flexibility:



  • You can configure the prompt line to your preference, e.g. you can specify a prompt symbol of your choice, add user or host name info, etc.

  • You can use Mímir with any shell of your choosing. The description says Bash and Zsh because these are the shells which I have tested Mímir on but technically you can use Mímir with any shell as long as it allows you to load a binary as a prompt.


Features



  • It is very fast: loads under 5ms with everything turned on (benchmark).

  • Shows current Git branch name.

  • Long directory paths are shortened and inaccessible paths are highlighted in red.

  • Kubernetes context and namespace info is shown using KUBECONFIG environment variable. If multiple config files are specified in the variable value then the first one with current context info is used. You can overwrite the K8s info by exporting the CURRENT_KUBE_CTX variable with an arbitrary value.

  • OpenStack cloud info is shown using the standard OpenStack environment variables that begin with OS_. Variables that specify IDs are used if name specifying variables are not available. E.g. OS_PROJECT_DOMAIN_ID would be used if OS_PROJECT_DOMAIN_NAME is not available. You can overwrite the cloud info by exporting the CURRENT_OS_CLOUD variable with an arbitrary value.


Installation


Installer script


The simplest way to install Mímir on Linux or macOS is to run:



$ sh -c "$(curl -sL git.io/getmimir)"


This will put the binary in /usr/local/bin/mimir


Pre-compiled binaries


Pre-compiled binaries for Linux and macOS are avaiable on the releases page.


The binaries are static executables.


Homebrew



$ brew install talal/tap/mimir


Building from source


The only required build dependency is Go 1.11 or above.



$ git clone https://github.com/talal/mimir.git
$ cd mimir
$ make install


This will put the binary in /usr/local/bin/mimir


Alternatively, you can also build Mímir directly with the go get command without manually cloning the repository:



$ go get -u github.com/talal/mimir


This will put the binary in $GOPATH/bin/mimir


Usage


The following usage examples are just one example of how Mímir can be configured. The examples below will result in a setup similar to the one shown in the demo above: the prompt symbol () changes to red if the previous command exited with an error.


Bash


Add this to your .bashrc file:



prompt_mimir_cmd() {
if [ $? != 0 ]; then
local prompt_symbol="\[\e[0;31m\]❯\[\e[0m\]"
else
local prompt_symbol="\[\e[0;35m\]❯\[\e[0m\]"
fi

PS1="$(/path/to/mimir)\n${prompt_symbol} "
}
PROMPT_COMMAND=prompt_mimir_cmd


Zsh


Add this to your .zshrc file:



autoload -Uz add-zsh-hook
prompt_mimir_cmd() { /path/to/mimir }
add-zsh-hook precmd prompt_mimir_cmd

prompt_symbol=''
PROMPT="%(?.%F{magenta}.%F{red})${prompt_symbol}%f "


Options
































Option Description Usage
MIMIR_DISABLE_KUBE Disable Kubernetes context and namespace info. export MIMIR_DISABLE_KUBE=1
MIMIR_DISABLE_CLOUD Disable OpenStack cloud info. export MIMIR_DISABLE_CLOUD=1
CURRENT_KUBE_CTX Display arbitrary info for K8s. export CURRENT_KUBE_CTX='custom info'
CURRENT_OS_CLOUD Display arbitrary info for OpenStack. export CURRENT_OS_CLOUD='custom info'

Credits


Most of the source code is borrowed from prettyprompt.

浏览 17
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报