diff --git a/misc/prompts.clifm b/misc/prompts.clifm index a69f10d7..f1c57610 100644 --- a/misc/prompts.clifm +++ b/misc/prompts.clifm @@ -6,8 +6,11 @@ # The regular prompt (just as the warning one, a secondary prompt used # to highlight invalid/non-existent command names) is built using command -# substitution ($(cmd)), string literals and/or one or more of the -# following escape sequences: +# substitution ($(cmd)), prompt modules (${module}), string literals, and +# escape sequences. +# +# 1. ESCAPE SEQUENCES +# ------------------- # # \e: Escape character # \u: The username @@ -91,7 +94,10 @@ # character, or by inserting its hex code: # echo -ne "paste_your_char" | hexdump -C -# COLORIZATION is made using either of the two following methods: +# 2. COLORS +# --------- +# +# Colorization is made using either of the two following methods: # 1) Bash-style full escape sequences (e.g. "\[\e[1;31m\]", for bold red) # # 2) Using the %{COLOR} syntax, where COLOR is: @@ -140,6 +146,26 @@ # scheme, you may want to edit the one you choose manually to make it fit # your current color scheme. +# 3. PROMPT MODULES AND COMMAND SUBSTITUTION +# ------------------------------------------ +# +# Since escape codes are limited and internal to Clifm, prompt modules and command +# substitution are designed to provide external information to the prompt. +# +# While command substitution work much like in regular shells, invoking shell +# commands (e.g. $(uname -s)), prompt modules are programs/scripts located in the +# plugins directory (etiher local or system wide). + +# To run a prompt module write "${NAME}". For example, to run the git prompt module: +# "${m_git_prompt_status}". Clifm will look for this module in the local plugins directory +# (~/.config/clifm/plugins), and, if not found, in the data directory (usually, +# /usr/local/share/clifm/plugins). Take a look at the "git" prompt for a concrete +# usage example. +# +# Note that you can also run a prompt module using command substitution, in which case +# you need to indicate the path to the module. For example: +# $(/usr/local/share/clifm/plugins/m_git_prompt_status) + [clifm] Notifications=true RegularPrompt="%{reset}\I[\S%{reset}]\l \A \u:\H %{cyan}\w%{reset}\n<\z%{reset}> %{blue}\$%{reset} " @@ -165,6 +191,12 @@ RegularPrompt="%{reset}\I[%{b:green}\u%{n:cyan}@%{b:green}\H%{reset}] %{b:blue}\ EnableWarningPrompt=true WarningPrompt="%{dim}\I[%{b:green}\u%{n:cyan}%{dim}@%{b:green}\H%{n:dim}] %{b:blue}\w %{b:red}!%{n:dim} " +[git] +Notifications=true +RegularPrompt="%{reset}[\S%{reset}] %{green}\f%{reset} ${m_git_prompt_status}\n<\z%{reset}> %{cyan}\$%{reset} " +EnableWarningPrompt=true +WarningPrompt="%{reset}%{b:red}(!)%{n:dim} > " + [pez] Notifications=true RegularPrompt="%{reset}\I[\S%{reset}]\l %{blue}\f%{reset} <\z%{reset}>\n%{b:red}>%{yellow}>%{green}>%{reset} " diff --git a/plugins/m_git_prompt_status b/plugins/m_git_prompt_status new file mode 100755 index 00000000..34620619 --- /dev/null +++ b/plugins/m_git_prompt_status @@ -0,0 +1,33 @@ +#!/bin/sh + +# Git prompt module for Clifm +# License: GPL3 +# Written by L. Abramovich + +branch="$(git branch --show-current 2>/dev/null)" + +[ -z "$branch" ] && exit 1 + +status="" + +for i in $(git status --porcelain | cut -c1-3 | uniq); do + case "$i" in + ".") status="${status}\e[36m+" ;; + "D"*) status="${status}\e[31mD" ;; + "M"*) status="${status}\e[32mM" ;; + "R"*) status="${status}\e[35mR" ;; + "U"*) status="${status}\e[33mU" ;; + "A"*) status="${status}\e[32mA" ;; + "??"*) status="${status}\e[31m?" ;; + esac +done + +# FIXME: The POSIX version of echo does not support flags +echo -ne "(\e[35m$branch\e[0m" +if [ -n "$status" ]; then + echo -e "\e[2;37m|\e[0m${status}\e[0m)" +else + echo -e ")\n" +fi + +exit 0