From 8a6f26ff9bd260101b56b1de39adbf5992fb27a8 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 17 Dec 2015 15:17:28 +0100 Subject: [PATCH] Document prompt_pwd Fixes #253 --- doc_src/prompt_pwd.txt | 28 ++++++++++++++++++++++++++++ share/functions/prompt_pwd.fish | 6 ++++++ 2 files changed, 34 insertions(+) create mode 100644 doc_src/prompt_pwd.txt diff --git a/doc_src/prompt_pwd.txt b/doc_src/prompt_pwd.txt new file mode 100644 index 000000000..7161d8aa9 --- /dev/null +++ b/doc_src/prompt_pwd.txt @@ -0,0 +1,28 @@ +\section prompt_pwd prompt_pwd - Print pwd suitable for prompt + +\subsection prompt_pwd-synopsis Synopsis +\fish{synopsis} +prompt_pwd +\endfish + +\subsection prompt_pwd-description Description + +prompt_pwd is a function to print the current working directory in a way suitable for prompts. It will replace the home directory with "~" and shorten every path component but the last to a default of one character. + +To change the number of characters per path component, set $fish_prompt_pwd_dir_length to the number of characters. Setting it to 0 or an invalid value will disable shortening entirely. + +\subsection prompt_pwd-example Examples + +\fish +>_ cd ~/ +>_ echo $PWD +/home/alfa +>_ prompt_pwd +~ +>_ cd /tmp/banana/sausage/with/mustard +>_ prompt_pwd +/t/b/s/w/mustard +>_ set -g fish_prompt_pwd_dir_length 3 +>_ prompt_pwd +/tmp/ban/sau/wit/mustard +\endfish diff --git a/share/functions/prompt_pwd.fish b/share/functions/prompt_pwd.fish index c519c6cc5..96e9b2f33 100644 --- a/share/functions/prompt_pwd.fish +++ b/share/functions/prompt_pwd.fish @@ -1,4 +1,10 @@ function prompt_pwd --description "Print the current working directory, shortened to fit the prompt" + set -q argv[1]; and switch $argv[1] + case -h --help + __fish_print_help prompt_pwd + return 0 + end + # This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1