kubie icon indicating copy to clipboard operation
kubie copied to clipboard

Feature Request: Consider support history maintaining to main-shell from sub-shells

Open Dentrax opened this issue 3 years ago • 9 comments

$ wc -l .zsh_history
   1 .zsh_history

$ tail -6 .zsh_history
: 1626419269:0;echo "Hello, World!"
$ kubie ctx foo
$ kubectl get pods -l app=bar -o wide
$ exit  #  exit sub-shell
$ tail -6 .zsh_history
: 1626419269:0;echo "Hello, World!"
: 1626418505:0;kubie ctx
: 1626419248:0;tail -6 .zsh_history

It would be a great feature if we are able to pass our command history to main shell in order to keep history maintained from sub-shells. Currently, we do not have access to any previous commands after we exit the sub-shell.

Dentrax avatar Jul 16 '21 07:07 Dentrax

@sbstp

As a workaround, I thought of a few possible solutions to handle this:

1. Merging the history of current session after exit

By creating a temp history file for the current session, we can easily cover this. We should append every command we write to that temporary file. In the merging stage, we can listen for the zshexit hook in order to append the whole $ZDOTDIR/.current_history to $HOME/.zsh_history. Rebasing by time is needed for the history file after merge operation?

2. Appending each command real-time

Is it make sense to append each command we write to under $HOME/.zsh_history? We can add a precmd hook for this.

3. Making sub-shell optional

Like the kubectx. Why wouldn't we make shell spawning optional? I might simply do not want to work under a new shell.

Dentrax avatar Jul 26 '21 19:07 Dentrax

Any thoughts? @sbstp Looking forward to this feature. 😍

Dentrax avatar Aug 26 '21 18:08 Dentrax

This feels like something that should be implemented outside of kubie. The sub-shell is required to inject a bunch of stuff into .bashrc when we launch the shell.

I'm not sure if real time history merging between multiple terminals is something that people actually want. But you should be able to setup your shell to merge history when it exists using plain old shell settings, like shown here.

sbstp avatar Sep 04 '21 19:09 sbstp

I think the reason why that happens comes from using a sub-shell in the first place. I recently looked at kubie how it is doing terminal window isolation etc. Using a sub-shell definitely has advantages that I did not consider when starting to implement kubeswitch 1.5 years ago. However, not launching a sub-shell also avoids problems such as this one. The shell history works across terminals + seeing a history of selected contexts (via switch h) works.

Anyways, kubie is a great tool and I guess has trade-offs and advantages like a lot of other software.

danielfoehrKn avatar Sep 25 '21 15:09 danielfoehrKn

Actually I don't understand why this is so complicated. Even with a sub shell, you can just point HISTFILE to its default value, and then it that case it will work as expected.

The decision of merging/sharing/appending history is controlled by the user https://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows.

Currently it would be great if kubie will offer an option to use the default HISTFILE instead of creating a copy of it, as this creates a bug where ideally merged history just disappears.

I currently bypassed this by:

cp ~/.zsh_history ~/.zsh_history_bypass_kubie
vim ~/.zshrc 
HISTFILE=~/.zsh_history_bypass_kubie
HISTSIZE=500000
SAVEHIST=500000
setopt appendhistory
setopt INC_APPEND_HISTORY  
setopt SHARE_HISTORY

Shaked avatar Oct 20 '21 12:10 Shaked

Kind ping here. 🤞 @sbstp

Dentrax avatar Feb 05 '22 11:02 Dentrax

I'd like to see this feature in kubie. Anyone has a bandwidth to submit a PR for this?

cc @sbstp

Dentrax avatar Dec 28 '22 12:12 Dentrax

Currently it would be great if kubie will offer an option to use the default HISTFILE instead of creating a copy of it, as this creates a bug where ideally merged history just disappears.

If you explicitly configure HISTFILE, what exactly is the problem? I am not entirely sure if I understand. I'm trying to get this fixed, but I don't see a problem if you have export HISTFILE="$HOME/.zsh_history. Yes, the history file will be copied, but zsh will write to the original file.

Alveel avatar Nov 24 '23 22:11 Alveel

Sorry, cc @Shaked (2 years later 😅)

Alveel avatar Nov 24 '23 22:11 Alveel