Skip to content

Commit

Permalink
Add --shell-up-key-binding hidden command argument and filter_mode_sh…
Browse files Browse the repository at this point in the history
…ell_up_key_binding configuration option to allow customizing the filter mode used when atuin is invoked from a shell up-key binding
  • Loading branch information
pdecat committed Dec 17, 2022
1 parent cdc51e7 commit 303cc99
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 9 deletions.
4 changes: 4 additions & 0 deletions atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub struct Settings {
pub session_path: String,
pub search_mode: SearchMode,
pub filter_mode: FilterMode,
pub filter_mode_shell_up_key_binding: FilterMode,
pub shell_up_key_binding: bool,
pub exit_mode: ExitMode,
// This is automatically loaded when settings is created. Do not set in
// config! Keep secrets and settings apart.
Expand Down Expand Up @@ -289,6 +291,8 @@ impl Settings {
.set_default("sync_address", "https://api.atuin.sh")?
.set_default("search_mode", "fuzzy")?
.set_default("filter_mode", "global")?
.set_default("filter_mode_shell_up_key_binding", "global")?
.set_default("shell_up_key_binding", false)?
.set_default("exit_mode", "return-original")?
.set_default("session_token", "")?
.set_default("style", "auto")?
Expand Down
12 changes: 11 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ auto_sync = true/false

### `update_check`

Configures whether or not to automatically check for updates. Defaults to
Configures whether or not to automatically check for updates. Defaults to
true.

```
Expand Down Expand Up @@ -143,6 +143,16 @@ Filter modes can still be toggled via ctrl-r
filter_mode = "host"
```

### `filter_mode_shell_up_key_binding`

The default filter to use when searching and being invoked from a shell up-key binding.

Accepts exactly the same options as `filter_mode` above

```
filter_mode_shell_up_key_binding = "session"
```

### `exit_mode`

What to do when the escape key is pressed when searching
Expand Down
5 changes: 5 additions & 0 deletions src/command/client/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub struct Cmd {
#[arg(long = "search-mode")]
search_mode: Option<SearchMode>,

/// Marker argument used to inform atuin that it was invoked from a shell up-key binding (hidden from help to avoid confusion)
#[arg(long = "shell-up-key-binding", hide = true)]
shell_up_key_binding: bool,

/// Use human-readable formatting for time
#[arg(long)]
human: bool,
Expand All @@ -79,6 +83,7 @@ impl Cmd {
if self.filter_mode.is_some() {
settings.filter_mode = self.filter_mode.unwrap();
}
settings.shell_up_key_binding = self.shell_up_key_binding;
if self.interactive {
let item = interactive::history(&self.query, settings, db).await?;
eprintln!("{item}");
Expand Down
6 changes: 5 additions & 1 deletion src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ pub async fn history(
input,
results_state: ListState::default(),
context: current_context(),
filter_mode: settings.filter_mode,
filter_mode: if settings.shell_up_key_binding {
settings.filter_mode_shell_up_key_binding
} else {
settings.filter_mode
},
update_needed,
};

Expand Down
4 changes: 2 additions & 2 deletions src/shell/atuin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ fi

if [[ -z ${ATUIN_NOBIND} ]]; then
bind -x '"\C-r": __atuin_history'
bind -x '"\e[A": __atuin_history --filter-mode session'
bind -x '"\eOA": __atuin_history --filter-mode session'
bind -x '"\e[A": __atuin_history --shell-up-key-binding'
bind -x '"\eOA": __atuin_history --shell-up-key-binding'
fi
4 changes: 2 additions & 2 deletions src/shell/atuin.fish
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function _atuin_postexec --on-event fish_postexec
end

function _atuin_search
set h (RUST_LOG=error atuin search -i -- (commandline -b) 3>&1 1>&2 2>&3)
set h (RUST_LOG=error atuin search $* -i -- (commandline -b) 3>&1 1>&2 2>&3)
commandline -f repaint
if test -n "$h"
commandline -r $h
Expand All @@ -33,7 +33,7 @@ function _atuin_bind_up
set -l lineno (commandline --line)
switch $lineno
case 1
_atuin_search
_atuin_search --shell-up-key-binding
case '*'
up-or-search
end
Expand Down
7 changes: 4 additions & 3 deletions src/shell/atuin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ _atuin_search(){
echoti rmkx
# swap stderr and stdout, so that the tui stuff works
# TODO: not this
output=$(RUST_LOG=error atuin search -i -- $BUFFER 3>&1 1>&2 2>&3)
# shellcheck disable=SC2048
output=$(RUST_LOG=error atuin search $* -i -- $BUFFER 3>&1 1>&2 2>&3)
echoti smkx

if [[ -n $output ]] ; then
Expand All @@ -54,6 +55,6 @@ if [[ -z $ATUIN_NOBIND ]]; then
bindkey '^r' _atuin_search_widget

# depends on terminal mode
bindkey '^[[A' _atuin_search_widget
bindkey '^[OA' _atuin_search_widget
bindkey '^[[A' _atuin_search_widget --shell-up-key-binding
bindkey '^[OA' _atuin_search_widget --shell-up-key-binding
fi

0 comments on commit 303cc99

Please sign in to comment.