mirror of
https://github.com/dvorka/hstr.git
synced 2025-02-22 13:53:16 +08:00
Fixed #114 by introducing HH_PROMPT variable allowing to customize hh prompt - thank you @livibetter.
This commit is contained in:
parent
8aac04e0ef
commit
791c652316
3 changed files with 45 additions and 31 deletions
46
README.md
46
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
|
||||
```
|
||||
|
|
7
man/hh.1
7
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
|
||||
|
||||
|
|
13
src/hstr.c
13
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);
|
||||
}
|
||||
|
||||
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));
|
||||
|
|
Loading…
Reference in a new issue