Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the commands that are run to the shell history. #19

Open
fpgmaas opened this issue Mar 29, 2023 · 1 comment
Open

Add the commands that are run to the shell history. #19

fpgmaas opened this issue Mar 29, 2023 · 1 comment

Comments

@fpgmaas
Copy link
Owner

fpgmaas commented Mar 29, 2023

Right now, the shell history will only show ckit. It might be desirable that the actual commands that are run are added to the command history.

The idea would be to also create a ~/$CKIT_HOME/config file when ckit init is run, where a variable is specified e.g. add_to_history=true. If this is set to True, ckit should aim to add the command to the shell history.

Potential issue here is that this might be shell specific, i.e. the requirements to make this happen differ between e.g. zsh and bash.

@mcmd1962
Copy link

mcmd1962 commented Apr 1, 2023

Suggestion is to look on how fzf does this. From this tool I compiled the following (which is only an idea, and far from complete/correct):

bind '"\C-r": " \C-e\C-u\C-y\ey\C-u`__ckit__`\e\C-e\er\e^"'

__echoerr() { echo "$@" 1>&2; }

__ckit__ () {
    ( local line;
    shopt -u nocaseglob nocasematch;
    line=$(__ckit_choice__)
    echo $line
    )
}


__ckit_choice__()  {
   __echoerr
   __echoerr 1: ls
   __echoerr 2: cd /tmp
   __echoerr 3: cd /var/tmp
   read -p "What command do you want to issue? " -n 1 -r
   __echoerr    # (optional) move to a new line
   if [[ $REPLY =~ ^[1]$ ]]; then
      echo ls
   elif [[ $REPLY =~ ^[2]$ ]]; then
      echo cd /tmp
   elif [[ $REPLY =~ ^[3]$ ]]; then
      echo cd /var/tmp
   fi
}

This approach, binding C-r (of maybe some other key) to your python script which will do it's magic and output the correct command to STDOUT, which can be executed by the shell.
Note: I donot fully understand the bind command, unfortunately this shows "__ckit__" on the command line, and I donot understand why this is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants