Skip to main content

This is a handler that runs on top of the Bash shell and implements command autocomplete using a dropdown list in real time.

Project description

рџ§  Intelli Shell рџђљ

This is a handler that runs on top of the Bash shell and implements command autocomplete using a dropdown list in real time.

You can view the history of executed commands with support for filtering and regular expressions, select and execute them from a list, and use directory navigation without leaving the current input line. In addition, it supports outputting variables, searching with filtering by the output of the last executed command, searching for executable commands and displaying a list of examples for them via cheet.sh.

I created this little project to make working with the console easier and faster. I haven't been able to find a solution for passing commands within a single session (examples can be found in the test directory).

Because execution of each individual command occurs in external and independent processes, some actions may not perform as you expect. For example, calling functions again in subsequent commands is not supported, nor are any interactive scripts that require the user to provide input.


вњЁ Implemented:

  • History filtering (takes into account the order of execution with duplicates excluded) and running the selected command (using the Enter button) from a drop-down list in an external process with support for recording executed commands in the history.
  • Support for regular expressions during filtering, taking into account the position of entered phrases in the command using the ^ character at the beginning or end of a line (by default, the search is performed regardless of the position of entered phrases separated by a space).
  • Navigation through directories using cd and selecting files for reading via cat, nano, vim and mcedit, as well as copying via cp and mv.
  • Captures and displays the execution time of the last executed command in the spirit of oh-my-bash.
  • A mechanism for storing and passing variables of the current process to an external executable process has been implemented (may work unstable), and also output of all variables via the $$ symbol is supported.
  • Integration with cheat.sh. Auto-complete search for executable commands using the ! or output cheat sheets for the last command entered in the line.
  • Interactive grep. Performs a filtered search based on the output of the last command executed when the @ character is used at the beginning of the input line. This can be used as an alternative to grep, which needs to be called every time the text in the filter query changes, or if you have previously used a soft terminal search but the output may have gone beyond it.

To read the output of the last command, a second thread is used. To compare performance on my 1 core system I used cat to read the output of a 160k lines file which takes on average 4 seconds, when using two threads the reading time increases on 300-400 milliseconds.

Use two ! characters at the end of a line and call it to get extended prompts with command comments or a brief syntax example.

/home/lifailon [0.009s] > test !!
# test
# Check file types and compare values.
# Returns 0 if the condition evaluates to true, 1 if it evaluates to false.
# More information: <https://www.gnu.org/software/coreutils/test>.

# Test if a given variable is equal to a given string:
test "$MY_VAR" == "/bin/zsh"

# Test if a given variable is empty:
test -z "$GIT_BRANCH"

# Test if a file exists:
test -f "path/to/file_or_directory"

# Test if a directory does not exist:
test ! -d "path/to/directory"

# If A is true, then do B, or C in the case of an error (notice that C may run even if A fails):
test condition && echo "true" || echo "false"

/home/lifailon [0.009s] > js function !!
 (function(){
   // code
 })();

 !function(){
   // code
 }();

 function(){
   // code
 }();

рџ’Ў To do:

  • Process all commands in one persistent bash process (for example, using pexpect).
  • Automatic addition of options for commands after the - character at the end of a line (for example, using compgen).

вЊЁпёЏ Hotkeys:

  • right – select a command without executing it, which is convenient for continuing recording or moving to the next directory to quickly display its contents.
  • backspace - in addition to deleting, updates the history to reflect the changes.
  • ctrl+c - clears the current input line (buffer) without moving to a new line and does not terminate the executed command (has no effect on stopping a running program, which can also be interrupted).
  • ctrl+l - completely clears the output console without affecting the input console and without changing the last execution command.
  • ctrl+q - hides the drop-down list until the next input.

рџљЂ Install from PyPi

For quick installation on your system, use the PyPi package manager:

pip install intellishell

To run use the command:

insh

рџ”Ё Install from GitHub

To work, you need to install the Python prompt-toolkit library on the system, which is responsible for creating a drop-down list:

pip install prompt_toolkit

If you have any difficulties with installation, please refer to the official manual.

Other dependencies in the form of external libraries are not required.

Download the script to the system and set access rights:

mkdir -p ~/.local/bin
curl -s https://raw.githubusercontent.com/Lifailon/intellishell/rsa/src/insh.py -o ~/.local/bin/insh
chmod +x ~/.local/bin/insh

Add the directory with the executables to the PATH environment variable, if not already done:

export PATH="$HOME/.local/bin:$PATH"
source ~/.bashrc

To run, use the insh command. If you get errors, simply change in hebang the version of the Python interpreter for which the prompt-toolkit library was installed:

pythonVersion=python3.10
sed -i '1s|^.*|#!/usr/bin/env '"$pythonVersion"'|' ~/.local/bin/insh
insh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

intellishell-0.4.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

intellishell-0.4.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file intellishell-0.4.0.tar.gz.

File metadata

  • Download URL: intellishell-0.4.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for intellishell-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b2a8b01a95c76b6201a59a76b24dfb2dd199de93a18edeabd610cb38fa2135bd
MD5 aac0e7f00588757729e230554b276ed0
BLAKE2b-256 e6d46cbfaebfa2a4aa5390948bd850633353a5c13dac5dfc3d36e5e64241296f

See more details on using hashes here.

File details

Details for the file intellishell-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: intellishell-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for intellishell-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7ba778fd1c13cce79dfa7f8cb65e23003d80e157d86742a06676be4594e7e3b
MD5 5064f8c52ae2c7df152c13d03fa0996f
BLAKE2b-256 d53a5fce4f1138fabe26b4c4dc4a409d567aa3dd2962e3198727f620bda12c51

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page