From 791c652316f6ef87a2b33343331d3e1673155c5f Mon Sep 17 00:00:00 2001 From: Martin Dvorak Date: Wed, 7 Jan 2015 22:15:21 +0100 Subject: [PATCH] Fixed #114 by introducing HH_PROMPT variable allowing to customize hh prompt - thank you @livibetter. --- README.md | 46 ++++++++++++++++++++++------------------------ man/hh.1 | 7 +++++++ src/hstr.c | 23 ++++++++++++++++------- 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index e43cbeb..3206c73 100644 --- a/README.md +++ b/README.md @@ -24,36 +24,36 @@ Enjoy [video](http://www.youtube.com/watch?v=sPF29NyXe2U) tutorial. UBUNTU INSTALLATION ------------------- -* install `hh` on Ubuntu (12.04LTS/12.10/13.10/14.04LTS): +Install `hh` on Ubuntu: ```bash sudo add-apt-repository ppa:ultradvorka/ppa sudo apt-get update sudo apt-get install hh ``` - -* optionally configure `hh`: +Optionally configure `hh`: ```bash hh --show-configuration >> ~/.bashrc ``` +Check the documentation: +```bash +man hh +``` INSTALLATION FROM SOURCE CODE ----------------------------- -* Clone Git repository: +Clone Git repository: ```bash git clone https://github.com/dvorka/hstr.git ``` - -* create build files using: +Create build files using: ```bash cd ./dist && ./1-dist.sh && cd .. ``` - -* install `hh` using: +Install `hh` using: ```bash ./configure && make && make install ``` - -* optionally configure `hh`: +Optionally configure `hh`: ```bash hh --show-configuration >> ~/.bashrc ``` @@ -61,16 +61,15 @@ hh --show-configuration >> ~/.bashrc DISTRIBUTION INSTALLATION ------------------------- -* download latest distribution from project Releases section: +Download latest distribution from project Releases section: https://github.com/dvorka/hstr/releases -* expand the archive and install `hh` using: +Expand the archive and install `hh` using: ```bash ./configure && make && make install ``` - -* optionally configure `hh`: +Optionally configure `hh`: ```bash hh --show-configuration >> ~/.bashrc ``` @@ -78,7 +77,7 @@ hh --show-configuration >> ~/.bashrc DEBIAN/MINT INSTALLATION ------------------- -* install `hh` on Debian (Wheezy) or Mint (13) by registering the key: +Install `hh` on Debian (Wheezy) or Mint (13) by registering the key: ```bash wget www.clfh.de/frankh.asc apt-key add frankh.asc @@ -93,8 +92,7 @@ and installing it: apt-get update apt-get install hh ``` - -* optionally configure `hh`: +Optionally configure `hh`: ```bash hh --show-configuration >> ~/.bashrc ``` @@ -102,15 +100,15 @@ hh --show-configuration >> ~/.bashrc ARCH LINUX ---------- -* download latest distribution from project Releases section: +Download latest distribution from project Releases section: https://github.com/dvorka/hstr/releases -* use PKGBUILD in the root of the distribution to build package using `makepkg`: +Use PKGBUILD in the root of the distribution to build package using `makepkg`: https://wiki.archlinux.org/index.php/PKGBUILD -* install `hh` +Install `hh` * optionally configure `hh`: ```bash hh --show-configuration >> ~/.bashrc @@ -118,21 +116,21 @@ hh --show-configuration >> ~/.bashrc MAC OS ------ -* install MacPorts: +Install MacPorts: http://www.macports.org -* set the environment: +Set the environment: ```bash env CFLAGS="-I/opt/local/include -I/usr/include" LDFLAGS="-L/opt/local/lib -L/usr/lib" ./configure ``` -* finish the installation +Finish the installation ```bash make && make install ``` -* optionally configure `hh`: +Optionally configure `hh`: ```bash hh --show-configuration >> ~/.bashrc ``` diff --git a/man/hh.1 b/man/hh.1 index c10c3f5..94dd971 100644 --- a/man/hh.1 +++ b/man/hh.1 @@ -105,6 +105,13 @@ Configuration options: Example: \fBexport HH_CONFIG=hicolor,regexp\fR +.TP +\fBHH_PROMPT\fR +Change prompt string which is "user@host$ " by default. + +Example: + \fBexport HH_PROMPT="$ "\fR + .SH FILES \fB~/.hh_favorites\fR bookmarked favorite commands diff --git a/src/hstr.c b/src/hstr.c index bb5671d..d143316 100644 --- a/src/hstr.c +++ b/src/hstr.c @@ -77,6 +77,7 @@ #define HH_COLOR_MATCH 5 #define HH_ENV_VAR_CONFIG "HH_CONFIG" +#define HH_ENV_VAR_PROMPT "HH_PROMPT" #define HH_CONFIG_MONO "monochromatic" #define HH_CONFIG_HICOLOR "hicolor" @@ -287,19 +288,27 @@ void hstr_get_env_configuration(Hstr *hstr) int print_prompt(Hstr *hstr) { - char *user = getenv(ENV_VAR_USER); - char *hostname=malloc(HOSTNAME_BUFFER); int xoffset = 0, promptLength; if(hstr->hicolor) { color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT)); color_attr_on(A_BOLD); } - user=(user?user:"me"); - get_hostname(HOSTNAME_BUFFER, hostname); - mvprintw(Y_OFFSET_PROMPT, xoffset, "%s@%s$ ", user, hostname); - promptLength=strlen(user)+1+strlen(hostname)+1+1; - free(hostname); + + char *prompt = getenv(HH_ENV_VAR_PROMPT); + if(prompt) { + mvprintw(Y_OFFSET_PROMPT, xoffset, "%s", prompt); + promptLength=strlen(prompt); + } else { + char *user = getenv(ENV_VAR_USER); + char *hostname=malloc(HOSTNAME_BUFFER); + user=(user?user:"me"); + get_hostname(HOSTNAME_BUFFER, hostname); + mvprintw(Y_OFFSET_PROMPT, xoffset, "%s@%s$ ", user, hostname); + promptLength=strlen(user)+1+strlen(hostname)+1+1; + free(hostname); + } + if(hstr->hicolor) { color_attr_off(A_BOLD); color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT));