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

Incognito mode #517

Open
conradludgate opened this issue Sep 1, 2022 · 7 comments
Open

Incognito mode #517

conradludgate opened this issue Sep 1, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@conradludgate
Copy link
Collaborator

I think it would be cool if we could do

atuin incognito

And spawn a subshell. In this subshell we will have syncing disabled, and we will be working with a local copy of our normal history database.

When you exit the subshell, the database is 'rolled back'. As if the commands were never run.

There could be a atuin incognito commit if you decide you want to keep the commands.

Scenario: you are playing around with a REST API in curl and need to use an auth token, but don't want to set up environment variables and don't want the token in your shell history

@conradludgate conradludgate added the enhancement New feature or request label Sep 1, 2022
@panekj
Copy link
Contributor

panekj commented Sep 1, 2022

fish has private mode

-P or --private
       Enables private mode: fish will not access old or store new history.

and sets fish_private_mode variable to 1

@conradludgate
Copy link
Collaborator Author

I think I would like to see existing history, but that could be a further flag I guess

@andrewcrook
Copy link

andrewcrook commented Sep 24, 2022

There needs to be something to add the ability to either pause logging or stop displaying history for things like sudo. May be an option to just filter out items containing configurable keywords such as ‘sudo’ or ‘supercooladmintool’.

However, I think people will want to pause the logging temperately.

@mozzieongit
Copy link
Contributor

mozzieongit commented Oct 7, 2022

I use the following function to toggle atuin history saving. Then I can use my terminal without the commands getting persisted in the database. Searching will still work in incognito mode.

Usage:
incognito to enable incognito and disable saving commands to atuin database. incognito d to disable incognito and continue saving commands to the database.

ZSH:

incognito () {
    if [[ $1 = disable ]] || [[ $1 == d ]]
    then
        add-zsh-hook precmd _atuin_precmd
        add-zsh-hook preexec _atuin_preexec
    else
        add-zsh-hook -d precmd _atuin_precmd
        add-zsh-hook -d preexec _atuin_preexec
    fi
}

If I want those commands to also not be saved in the shell history file, I also enter export HISTFILE= (to empty the HISTFILE variable, which stores the file to which zsh will write history)

Bash:

incognito () {
  if [[ $1 = disable ]] || [[ $1 == d ]]
  then
    # disable incognito
    if [[ -n "${BLE_VERSION-}" ]]; then
      echo "no idea what ble is (no incognito mode available here)"
    else
      precmd_functions+=(_atuin_precmd)
      preexec_functions+=(_atuin_preexec)
    fi
  else
    # enable incognito
    if [[ -n "${BLE_VERSION-}" ]]; then
      echo "no idea what ble is (no incognito mode available here)"
    else
      precmd_functions=("${precmd_functions[@]/_atuin_precmd}")
      preexec_functions=("${preexec_functions[@]/_atuin_preexec}")
    fi
  fi
}

For fish, it would be this (I'm no fish user, so this could be a bit janky), though you would have to modify the functions, when they change in the future:

function incognito
    if [ "$argv[1]" = d -o "$argv[1]" = disable ]
        # disable incognito and re-set the functions to the atuin functions
        function _atuin_preexec --on-event fish_preexec
            set -gx ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
        end

        function _atuin_postexec --on-event fish_postexec
            set s $status
            if test -n "$ATUIN_HISTORY_ID"
                RUST_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null &
                disown
            end
        end
    else
        # enable incognito and empty the atuin functions
        function _atuin_preexec --on-event fish_preexec
            :
        end

        function _atuin_postexec --on-event fish_postexec
            :
        end
    end
end

@millette
Copy link
Contributor

As I mentionned in #467 in bash you can prevent commands from entering history when you precede them with a space.

@ellie
Copy link
Member

ellie commented Oct 13, 2022

As I mentionned in #467 in bash you can prevent commands from entering history when you precede them with a space.

This works with atuin too

@YummyOreo
Copy link
Contributor

what about instead of spawning a new shell, you first create a copy of the db w/ the ATUIN_SESSION value in it's name. this will act as the incognito db for that session. Then when the db is accessed, it the db for that session exists, you use that instead. And for sync you just don't do it if the db exists.

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

No branches or pull requests

7 participants