Initial HSTR version which works w/o TIOCSTI #478

This commit is contained in:
Martin Dvorak 2023-04-09 11:56:19 +02:00
parent 83e7d6ce1a
commit 2665ea6033
10 changed files with 183 additions and 63 deletions

View file

@ -1,7 +1,7 @@
2023-04-02 Martin Dvorak <martin.dvorak@mindforger.com>
2023-04-10 Martin Dvorak <martin.dvorak@mindforger.com>
* Released v3.0.0 - important fix release ensuring that HSTR will work
on operating systems and Linux kernels without TIOCSTI support.
* Released v3.0.0 - important release which adds ability of HSTR to work
on operating systems and Linux kernels without ioctl/TIOCSTI support.
2022-12-11 Martin Dvorak <martin.dvorak@mindforger.com>

View file

@ -1,4 +1,5 @@
# Installation
Install:
* [Ubuntu](#ubuntu)
@ -37,13 +38,17 @@ Tarball:
Upgrade:
* [HSTR 1.x to 2.x](#upgrade)
* [HSTR 1.x to 2.x](#hstr-1-x-to-2-x--from-hh-to-hstr)
* [HSTR 2.x to 3.x](#hstr-2-x-to-3-x--ioctl---tiocsti)
# Install
Install HSTR using a [package](https://pkgs.org/search/?q=hstr) or repository.
## Ubuntu
HSTR is [included in Ubuntu 21.10](https://packages.ubuntu.com/search?keywords=hstr) and [newer](https://wiki.ubuntu.com/Releases) releases:
```
```bash
sudo apt install hstr
```
@ -66,9 +71,10 @@ sudo apt-get install hstr
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Debian/Mint
HSTR is [included in Debian 11](https://packages.debian.org/bullseye/hstr) and [newer](https://www.debian.org/releases/) releases:
```
```bash
sudo apt install hstr
```
@ -107,13 +113,14 @@ apt-get install libncursesw5 libtinfo5
sudo dpkg -i hstr.deb
```
## Fedora/RHEL/CentOS/Scientific
Install HSTR on [Fedora](https://src.fedoraproject.org/rpms/hstr), RHEL, CentOS or Scientific Linux:
```bash
sudo dnf install hstr
```
... or:
```bash
@ -132,6 +139,7 @@ sudo dnf install ./hstr-<major>.<minor>.<revision>-2.x86_64.rpm
```
## openSUSE
To install HSTR on openSUSE, please check [software.opensuse.org](https://software.opensuse.org/package/hstr) or [pkgs.org](https://pkgs.org/search/?q=hstr). You can install HSTR as follows:
```bash
@ -141,7 +149,9 @@ zypper install hstr
```
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Gentoo
To install HSTR on Gentoo run (HSTR has been added to [Portage](https://bugs.gentoo.org/show_bug.cgi?id=527122)):
```bash
@ -161,6 +171,7 @@ apk add hstr
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## ALT Linux
To install HSTR on ALT Linux, please check [pkgs.org](https://pkgs.org/search/?q=hstr). You can install HSTR as follows:
```bash
@ -173,7 +184,9 @@ sudo apt-get install hstr
```
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Arch/Manjaro Linux
To install HSTR on Arch or Manjaro Linux download the latest distribution either from [pkgs.org](https://pkgs.org/search/?q=hstr) or [GitHub releases](https://github.com/dvorka/hstr/releases).
Use [PKGBUILD](https://wiki.archlinux.org/index.php/PKGBUILD) in the root of the distribution to build package using `makepkg`.
@ -181,6 +194,7 @@ Use [PKGBUILD](https://wiki.archlinux.org/index.php/PKGBUILD) in the root of the
To install HSTR from the [Arch User Repository (AUR)](https://aur.archlinux.org/packages/hstr-git/) run `yaourt -S hstr-git` in command line.
## FreeBSD
To install HSTR on FreeBSD, please check [pkgs.org](https://pkgs.org/search/?q=hstr). You can install HSTR as follows:
```bash
@ -188,7 +202,9 @@ pkg install hstr
```
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Slackware
To install HSTR on Slackware, please check [pkgs.org](https://pkgs.org/search/?q=hstr). You can install HSTR as follows:
```bash
@ -196,7 +212,9 @@ upgradepkg --install-new hstr-<major>.<minor>-x86_64-1cf.txz
```
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Void Linux
To install HSTR on Void Linux, please check [pkgs.org](https://pkgs.org/search/?q=hstr). You can install HSTR as follows:
```bash
@ -204,7 +222,9 @@ xbps-install -Su hstr
```
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Milis Linux
To install HSTR on Milis Linux run the following commands as root:
```bash
@ -214,12 +234,15 @@ mps kur hstr
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Haiku OS
To install HSTR on Haiku OS use [Haiku Depot](https://www.haiku-os.org/docs/userguide/en/applications/haikudepot.html):
* https://depot.haiku-os.org/#!/?srchexpr=hstr
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## macOS
Install HSTR on macOS using [Homebrew](https://brew.sh/) ([formula](https://formulae.brew.sh/formula/hstr)):
```bash
@ -235,6 +258,7 @@ sudo port install hstr
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## nix package manager
To install HSTR using the [nix package manager](https://nixos.org/nix/) e.g. on [NixOS](https://nixos.org/) you can use the [nix derivation for HSTR](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hstr/default.nix):
```bash
@ -244,6 +268,7 @@ nix-env -i hstr
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Guix package manager
To install HSTR in [GuixSD](https://www.gnu.org/software/guix/) or using the standalone [Guix package manager](https://www.gnu.org/software/guix/manual/en/html_node/Binary-Installation.html#Binary-Installation) you can install the `hstr` package, e.g.
```bash
@ -253,6 +278,7 @@ guix package -i hstr
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## MPR package manager
To install HSTR in Ubuntu or derivative operating systems using MPR, you can search for `hstr-git` using helper
or install it manually using `makedeb -s`
@ -261,9 +287,11 @@ or install it manually using `makedeb -s`
[MPR package](https://mpr.hunterwittenborn.com/packages/hstr-git)
# Build
Build HSTR from source code.
## Build on any Linux distro
Clone Git repository:
```bash
@ -285,6 +313,7 @@ Build and install HSTR using:
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Build snap
To build [snap](https://snapcraft.io/) for HSTR first clone Git repository:
```bash
@ -298,7 +327,7 @@ distribution.
Install [snapcraft](https://snapcraft.io/) and build
snap by running snapcraft in the root of Git repository:
```
```bash
$ ls ./snap
snapcraft.yaml
$ snapcraft
@ -308,6 +337,7 @@ $ snapcraft
Find `hstr_0+git..._amd64.snap` in the current directory.
## Build on Ubuntu
To build HSTR on Ubuntu clone Git repository:
```bash
@ -334,8 +364,8 @@ Build and install HSTR using:
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Build on Debian
To build HSTR on Debian clone Git repository:
```bash
@ -360,10 +390,10 @@ Build and install HSTR using:
./configure && make && make install
```
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Build on Fedora
To build HSTR on Fedora clone Git repository:
```bash
@ -391,6 +421,7 @@ Build and install HSTR using:
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Build on WSL
To build HSTR on [Windows Subsystem for Linux (WSL)](https://msdn.microsoft.com/en-us/commandline/wsl/about) clone Git repository:
```bash
@ -428,6 +459,7 @@ Make sure to **run** HSTR using <kbd>Ctrl-r</kbd> (or `hstrwsl`) - otherwise com
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Build on Cygwin
To build HSTR on [Cygwin](https://www.cygwin.com) clone Git repository:
```bash
@ -457,7 +489,9 @@ hstr --show-configuration >> ~/.bashrc
Make sure to **run** HSTR using <kbd>Ctrl-r</kbd> (or `hstrcygwin`) - otherwise commands will not appear in prompt.
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
## Build on macOS
HSTR can be built on macOS either using [MacPorts](https://www.macports.org/) or [Homebrew](https://brew.sh/).
---
@ -492,9 +526,11 @@ make
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
# Tarball
Download and install HSTR tarball.
## Build and Install Tarball
Download latest tarball from [GitHub releases](https://github.com/dvorka/hstr/releases) section.
Expand the archive and install HSTR using:
@ -503,7 +539,32 @@ Expand the archive and install HSTR using:
```
[Configure](CONFIGURATION.md) HSTR and check its [man page](README.md#documentation).
# Upgrade
HSTR major versions upgrades instructions.
## HSTR 1.x to 2.x: from HH to HSTR
Upgrade HSTR using a [package](https://pkgs.org/search/?q=hstr) or repository. If you are `HSTR 1.x` user, please read about [HSTR 2.x changes](https://github.com/dvorka/hstr/releases/tag/2.0).
## HSTR 2.x to 3.x: ioctl / TIOCSTI
`TIOCSTI` is an acronym for "Terminal Input Output Control STack Input",
and it is a system call used in Unix-like operating systems. The `TIOCSTI`
system call allows to insert data into the input buffer of a terminal
as if it had been typed by the user.
`TIOCSTI` is NOT available at:
* Linux kernel >=6.2.0
* Cygwin
* WSL
HSTR uses `TIOCSTI` to insert a command chosen by the user in HSTR
to shell prompt - if `TIOCSTI` is available. Otherwise shell specific
line editors features are used.
**Therefore it is important to configure HSTR after the installation:**
* [HSTR configuration](README.md#configuration)

View file

@ -1,4 +1,5 @@
# HSTR
[![GitHub Actions CI for Ubuntu](https://github.com/dvorka/hstr/actions/workflows/build_ubuntu.yml/badge.svg)](https://github.com/dvorka/hstr/actions)
[![Current release](https://img.shields.io/github/release/dvorka/hstr.svg)](https://github.com/dvorka/hstr/releases)
[![GitHub issues](https://img.shields.io/github/issues/dvorka/hstr.svg?maxAge=360)](https://github.com/dvorka/hstr/issues)
@ -11,14 +12,14 @@ Easily view, navigate and search your **command history** with shell history sug
[![Shell History Suggest Box](doc/hstr-v2.gif "Shell History Suggest Box @ YouTube")](http://www.youtube.com/watch?v=sPF29NyXe2U)
## Description
Are you looking for a command that you used **recently**? Do you
want to avoid the need to write **long commands** over and over
again? Are you looking for a tool that is able to manage your
**favorite** commands?
HSTR (**H**i**ST**o**R**y) is a command line utility that brings improved `bash`/`zsh` command completion
from the history. It aims to make completion **easier** and more **efficient**
than <kbd>Ctrl-r</kbd>.
from the history. It aims to make completion **easier** and more **efficient** than <kbd>Ctrl-r</kbd>.
HSTR can also **manage** your command history (for instance you can remove
commands that are obsolete or contain a piece of sensitive information)
@ -26,8 +27,8 @@ or **bookmark** your favorite commands.
<!-- Check [video](http://www.youtube.com/watch?v=sPF29NyXe2U) tutorial. -->
## Installation
Install:
* [Ubuntu](INSTALLATION.md#ubuntu)
@ -69,8 +70,8 @@ Tarball:
Check also [packages](https://pkgs.org/search/?q=hstr) for Linux and Unix.
## Configuration
Configure HSTR just by running:
```bash
@ -80,14 +81,15 @@ hstr --show-configuration >> ~/.bashrc
# zsh
hstr --show-configuration >> ~/.zshrc
```
For detailed HSTR configuration documentation please refer to [Configuration](CONFIGURATION.md).
## In the News
Read about HSTR in [LinuxMagazine](http://www.linux-magazine.com/Issues/2014/164/Bash-History-on-Steroids), [UbuntuGeek](http://www.ubuntugeek.com/tag/hstr-bash-history), [DebianAdmin](http://www.debianadmin.com/hstr-easily-view-navigate-search-and-use-your-command-history-with-shell-history.html), [Tuxdiary](http://tuxdiary.com/2015/02/17/hstr/), [Softpedia](http://linux.softpedia.com/get/Terminals/BASH-Command-History-Completion-103155.shtml) and [OSTechNix](https://www.ostechnix.com/hstr-easily-view-navigate-search-manage-commandline-history/).
## Documentation
Check man page:
```bash
@ -96,6 +98,6 @@ man hstr
User videos: [Zack](https://www.youtube.com/watch?v=Qd75pIeQkH8), [Dvorka](https://www.youtube.com/watch?v=sPF29NyXe2U) and [Yu-Jie Lin](https://www.youtube.com/watch?v=Qx5n_5B5xUw).
## Bugs
https://github.com/dvorka/hstr/issues

View file

@ -31,30 +31,36 @@ Insert custom command to terminal prompt and exit
Show favorites view immediately
.TP
\fB-s --show-configuration\fR
Show configuration that can be added to ~/.bashrc
.TP
Show configuration to be added to the config file of the shell (~/.bashrc or ~/.zshrc)
.TP
\fB-B --show-bash-configuration\fR
Show Bash configuration to be added to ~/.bashrc
.TP
\fB-Z --show-zsh-configuration\fR
Show Zsh configuration to be added to ~/.zshrc
.TP
\fB-b --show-blacklist\fR
Show blacklist of commands to be filtered out before history processing
.TP
.TP
\fB-V --version\fR
Show version information
.SH KEYS
.TP
.TP
\fBpattern\fR
Type to filter shell history.
.TP
.TP
\fBCtrl\-e\fR
Toggle regular expression and substring search.
.TP
.TP
\fBCtrl\-t\fR
Toggle case sensitive search.
.TP
.TP
\fBCtrl\-/\fR, \fBCtrl\-7\fR
Rotate view of history as provided by bash, ranked history ordered by the number of occurrences/length/timestamp and favorites.
.TP
.TP
\fBCtrl\-f\fR
Add currently selected command to favorites.
.TP
.TP
\fBCtrl\-l\fR
Toggle search pattern case.
.TP
@ -181,7 +187,28 @@ Example:
Commands to be hidden.
.SH BASH CONFIGURATION
Optionally add the following lines to ~/.bashrc:
Add the following lines to ~/bashrc if TIOCSTI is not supported by your OS:
.nf
.sp
alias hh=hstr # hh to be alias for hstr
export HSTR_CONFIG=hicolor # get more colors
shopt -s histappend # append new history items to .bash_history
export HISTCONTROL=ignorespace # leading space hides commands from history
export HISTFILESIZE=10000 # increase history file size (default is 500)
export HISTSIZE=${HISTFILESIZE} # increase history size (default is 500)
# ensure synchronization between bash memory and history file
export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
function hstrnotiocsti {
{ HSTR_OUT="$( { </dev/tty hstr ${READLINE_LINE}; } 2>&1 1>&3 3>&- )"; } 3>&1;
READLINE_LINE="$(hstr ${READLINE_LINE})"
READLINE_POINT=${#READLINE_LINE}
}
# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
if [[ $- =~ .*i.* ]]; then bind -x '"\C-r": "hstrnotiocsti"'; fi
export HSTR_TIOCSTI=n
.sp
.fi
Optionally add the following lines to ~/.bashrc if TIOCSTI is supported by your OS:
.nf
.sp
alias hh=hstr # make hh alias of hstr
@ -197,7 +224,25 @@ if [[ $\- =~ .*i.* ]]; then bind '"\eC\-r": "\eC\-a hstr -- \eC-j"'; fi
.sp
.fi
.SH ZSH CONFIGURATION
Optionally add the following lines to ~/.zshrc:
Add the following lines to ~/zshrc if TIOCSTI is not supported by your OS:
.nf
.sp
alias hh=hstr # hh to be alias for hstr
setopt histignorespace # skip cmds w/ leading space from history
export HSTR_CONFIG=hicolor # get more colors
hstr_no_tiocsti() {
zle -I
{ HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )"; } 3>&1;
BUFFER="${HSTR_OUT}"
CURSOR=${#BUFFER}
zle redisplay
}
zle -N hstr_no_tiocsti
bindkey '\C-r' hstr_no_tiocsti
export HSTR_TIOCSTI=n
.sp
.fi
Optionally add the following lines to ~/.zshrc if TIOCSTI is supported by your OS:
.nf
.sp
export HSTR_CONFIG=hicolor # get more colors
@ -217,10 +262,10 @@ bindkey -s "\eC\-r" "\eC\-a hstr \-\- \eC\-j" # bind hstr to Ctrl-r (for Vi mode
Print history items containing 'git' to standard output and exit.
.TP
\fBhstr --show-configuration >> ~/.bashrc\fR
Append default \fBhstr\fR configuration to your bash profile.
Append default \fBhstr\fR configuration to your Bash profile.
.TP
\fBhstr --show-configuration >> ~/.zhrc\fR
Append default \fBhstr\fR configuration to your zsh profile.
Append default \fBhstr\fR configuration to your Zsh profile.
.TP
\fBhstr --show-blacklist\fR
Show blacklist configured for history processing.

View file

@ -137,7 +137,7 @@
// major.minor.revision
static const char* VERSION_STRING=
"hstr version \"3.0.0\" (2023-04-05T08:50:00)"
"hstr version \"3.0.0\" (2023-04-08T08:50:00)"
"\n";
static const char* HSTR_VIEW_LABELS[]={
@ -176,8 +176,7 @@ static const char* INSTALL_BASH_CODE_PREFIX=
// across different bash sessions.
// -c -r ... Forces entire .bash_history to be reloaded (handles history deletes, synchronizes different bash sessions)
"\n# ensure synchronization between bash memory and history file"
"\nexport PROMPT_COMMAND=\"history -a; history -n; ${PROMPT_COMMAND}\""
"\n# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)";
"\nexport PROMPT_COMMAND=\"history -a; history -n; ${PROMPT_COMMAND}\"";
// zsh doc: http://zsh.sourceforge.net/Guide/zshguide.html
static const char* INSTALL_ZSH_CODE_PREFIX=
@ -192,16 +191,17 @@ static const char* HELP_STRING=
"Usage: hstr [option] [arg1] [arg2]..."
"\nShell history suggest box:"
"\n"
"\n --favorites -f ... show favorites view"
"\n --kill-last-command -k ... delete last command in history"
"\n --non-interactive -n ... print filtered history and exit"
"\n --show-configuration -s ... show configuration to be added to ~/.bashrc"
"\n --show-zsh-configuration -z ... show zsh configuration to be added to ~/.zshrc"
"\n --show-blacklist -b ... show commands to skip on history indexation"
"\n --is-tiocsti -t ... detect whether TIOCSTI is supported and print y or n"
"\n --insert-in-terminal=[c] -i ... insert command c in terminal prompt and exit"
"\n --version -V ... show version details"
"\n --help -h ... help"
"\n --favorites -f ... show favorites view"
"\n --kill-last-command -k ... delete last command in history"
"\n --non-interactive -n ... print filtered history and exit"
"\n --show-configuration -s ... show configuration to be added to ~/.bashrc"
"\n --show-bash-configuration -B ... show bash configuration to be added to ~/.bashrc"
"\n --show-zsh-configuration -Z ... show zsh configuration to be added to ~/.zshrc"
"\n --show-blacklist -b ... show commands to skip on history indexation"
"\n --is-tiocsti -t ... detect whether TIOCSTI is supported and print y or n"
"\n --insert-in-terminal=[c] -i ... insert command c in terminal prompt and exit"
"\n --version -V ... show version details"
"\n --help -h ... help"
"\n"
"\nReport bugs to martin.dvorak@mindforger.com"
"\nHome page: https://github.com/dvorka/hstr"
@ -216,17 +216,18 @@ static const char* LABEL_HELP=
#define GETOPT_OPTIONAL_ARGUMENT 2
static const struct option long_options[] = {
{"favorites", GETOPT_NO_ARGUMENT, NULL, 'f'},
{"kill-last-command", GETOPT_NO_ARGUMENT, NULL, 'k'},
{"version", GETOPT_NO_ARGUMENT, NULL, 'V'},
{"help", GETOPT_NO_ARGUMENT, NULL, 'h'},
{"non-interactive", GETOPT_NO_ARGUMENT, NULL, 'n'},
{"show-configuration", GETOPT_NO_ARGUMENT, NULL, 's'},
{"show-zsh-configuration", GETOPT_NO_ARGUMENT, NULL, 'z'},
{"show-blacklist", GETOPT_NO_ARGUMENT, NULL, 'b'},
{"is-tiocsti", GETOPT_NO_ARGUMENT, NULL, 't'},
{"insert-in-terminal", GETOPT_REQUIRED_ARGUMENT, NULL, 'i'},
{0, 0, NULL, 0 }
{"favorites", GETOPT_NO_ARGUMENT, NULL, 'f'},
{"kill-last-command", GETOPT_NO_ARGUMENT, NULL, 'k'},
{"version", GETOPT_NO_ARGUMENT, NULL, 'V'},
{"help", GETOPT_NO_ARGUMENT, NULL, 'h'},
{"non-interactive", GETOPT_NO_ARGUMENT, NULL, 'n'},
{"show-configuration", GETOPT_NO_ARGUMENT, NULL, 's'},
{"show-bash-configuration", GETOPT_NO_ARGUMENT, NULL, 'B'},
{"show-zsh-configuration", GETOPT_NO_ARGUMENT, NULL, 'Z'},
{"show-blacklist", GETOPT_NO_ARGUMENT, NULL, 'b'},
{"is-tiocsti", GETOPT_NO_ARGUMENT, NULL, 't'},
{"insert-in-terminal", GETOPT_REQUIRED_ARGUMENT, NULL, 'i'},
{0, 0, NULL, 0 }
};
typedef struct {
@ -363,10 +364,11 @@ void print_bash_install_code(void)
#else
"\nfunction hstrnotiocsti {"
#endif
"\n { HSTR_OUT=\"$( { </dev/tty hstr ${READLINE_LINE}; } 2>&1 1>&3 3>&- )\"; } 3>&1;"
"\n READLINE_LINE=\"$(hstr ${READLINE_LINE})\""
"\n READLINE_POINT=${#READLINE_LINE}"
"\n}"
"\n# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)"
#if defined(__MS_WSL__)
"\nif [[ $- =~ .*i.* ]]; then bind -x '\"\\C-r\": \"hstrwsl\"'; fi"
@ -398,10 +400,12 @@ void print_zsh_install_code(void)
#elif defined(__CYGWIN__)
"\nhstr_cygwin() {"
#else
"\nhstr_notiocsti() {"
"\nhstr_no_tiocsti() {"
#endif
"\n BUFFER=\"$(hstr ${BUFFER})\""
"\n zle -I"
"\n { HSTR_OUT=\"$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )\"; } 3>&1;"
"\n BUFFER=\"${HSTR_OUT}\""
"\n CURSOR=${#BUFFER}"
"\n zle redisplay"
"\n}"
@ -413,8 +417,8 @@ void print_zsh_install_code(void)
"\nzle -N hstr_cygwin"
"\nbindkey '\\C-r' hstr_cygwin"
#else
"\nzle -N hstr_notiocsti"
"\nbindkey '\\C-r' hstr_notiocsti"
"\nzle -N hstr_no_tiocsti"
"\nbindkey '\\C-r' hstr_no_tiocsti"
#endif
);
printf("\nexport HSTR_TIOCSTI=n");
@ -1643,6 +1647,7 @@ void loop_to_select(void)
fill_terminal_input("\"", FALSE);
}
if(executeResult) {
// TODO w/o TIOCSTI the command is NOT executed, just shown in the prompt
fill_terminal_input("\n", FALSE);
}
}
@ -1688,7 +1693,7 @@ void hstr_interactive(void)
void hstr_getopt(int argc, char **argv)
{
int option_index = 0;
int option = getopt_long(argc, argv, "fkVhnszbti", long_options, &option_index);
int option = getopt_long(argc, argv, "fkVhnsBZbti", long_options, &option_index);
if(option != -1) {
switch(option) {
case 'f':
@ -1730,7 +1735,11 @@ void hstr_getopt(int argc, char **argv)
printf("%s", HELP_STRING);
hstr_exit(EXIT_SUCCESS);
break;
case 'z':
case 'B':
print_bash_install_code();
hstr_exit(EXIT_SUCCESS);
break;
case 'Z':
print_zsh_install_code();
hstr_exit(EXIT_SUCCESS);
break;

View file

@ -149,7 +149,10 @@ void tiocsti(void)
char buf[] = DEFAULT_COMMAND;
unsigned i;
for (i=0; i<sizeof buf-1; i++) {
ioctl(0, TIOCSTI, &buf[i]);
if (ioctl(0, TIOCSTI, &buf[i]) < 0) {
perror("Unable to execute TIOCSTI using ioctl()");
exit(1);
}
}
}
#endif

View file

@ -86,7 +86,7 @@ int hstr_strlen(const char* s);
char* hstr_strelide(char* buffer, const char* s, unsigned maxlength);
void hstr_chop(char* s);
bool is_tiocsti_supported(void);
#ifndef __CYGWIN__
#if !defined(__MS_WSL__) && !defined(__CYGWIN__)
void tiocsti(void);
#endif
void fill_terminal_input(char* cmd, bool padding);