fpgmaas/ckit

Add the commands that are run to the shell history.

Opened this issue · 1 comments

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.

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.