use Ctrl-n instead of Alt-n on macOS (#1106)

* use Ctrl-n instead of Alt-n on macOS

* make ctrl-n instead of alt-n configurable
This commit is contained in:
Richard Turner 2023-07-27 09:10:40 +01:00 committed by GitHub
parent 9c7501bbd3
commit c0449955e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 1 deletions

View file

@ -68,6 +68,10 @@
## number of context lines to show when scrolling by pages ## number of context lines to show when scrolling by pages
# scroll_context_lines = 1 # scroll_context_lines = 1
## use ctrl instead of alt as the shortcut modifier key for numerical UI shortcuts
## alt-0 .. alt-9
# ctrl_n_shortcuts = false
## prevent commands matching any of these regexes from being written to history. ## prevent commands matching any of these regexes from being written to history.
## Note that these regular expressions are unanchored, i.e. if they don't start ## Note that these regular expressions are unanchored, i.e. if they don't start
## with ^ or end with $, they'll match anywhere in the command. ## with ^ or end with $, they'll match anywhere in the command.

View file

@ -168,6 +168,7 @@ pub struct Settings {
#[serde(with = "serde_regex", default = "RegexSet::empty")] #[serde(with = "serde_regex", default = "RegexSet::empty")]
pub cwd_filter: RegexSet, pub cwd_filter: RegexSet,
pub workspaces: bool, pub workspaces: bool,
pub ctrl_n_shortcuts: bool,
// This is automatically loaded when settings is created. Do not set in // This is automatically loaded when settings is created. Do not set in
// config! Keep secrets and settings apart. // config! Keep secrets and settings apart.
@ -380,6 +381,7 @@ impl Settings {
.set_default("shell_up_key_binding", false)? .set_default("shell_up_key_binding", false)?
.set_default("session_token", "")? .set_default("session_token", "")?
.set_default("workspaces", false)? .set_default("workspaces", false)?
.set_default("ctrl_n_shortcuts", false)?
.add_source( .add_source(
Environment::with_prefix("atuin") Environment::with_prefix("atuin")
.prefix_separator("_") .prefix_separator("_")

View file

@ -102,6 +102,9 @@ impl State {
let ctrl = input.modifiers.contains(KeyModifiers::CONTROL); let ctrl = input.modifiers.contains(KeyModifiers::CONTROL);
let alt = input.modifiers.contains(KeyModifiers::ALT); let alt = input.modifiers.contains(KeyModifiers::ALT);
// Use Ctrl-n instead of Alt-n?
let modfr = if settings.ctrl_n_shortcuts { ctrl } else { alt };
// reset the state, will be set to true later if user really did change it // reset the state, will be set to true later if user really did change it
self.switched_search_mode = false; self.switched_search_mode = false;
match input.code { match input.code {
@ -115,7 +118,7 @@ impl State {
KeyCode::Enter => { KeyCode::Enter => {
return Some(self.results_state.selected()); return Some(self.results_state.selected());
} }
KeyCode::Char(c @ '1'..='9') if alt => { KeyCode::Char(c @ '1'..='9') if modfr => {
let c = c.to_digit(10)? as usize; let c = c.to_digit(10)? as usize;
return Some(self.results_state.selected() + c); return Some(self.results_state.selected() + c);
} }

View file

@ -231,3 +231,12 @@ history_filter = [
"^innocuous-cmd .*--secret=.+" "^innocuous-cmd .*--secret=.+"
] ]
``` ```
## macOS <kbd>Ctrl-n</kbd> key shortcuts
macOS does not have an <kbd>Alt</kbd> key, although terminal emulators can often be configured to map the <kbd>Option</kbd> key to be used as <kbd>Alt</kbd>. *However*, remapping <kbd>Option</kbd> this way may prevent typing some characters, such as using <kbd>Option-3</kbd> to type `#` on the British English layout. For such a scenario, set the `ctrl_n_shortcuts` option to `true` in your config file to replace <kbd>Alt-0</kbd> to <kbd>Alt-9</kbd> shortcuts with <kbd>Ctrl-0</kbd> to <kbd>Ctrl-9</kbd> instead:
```
# Use Ctrl-0 .. Ctrl-9 instead of Alt-0 .. Alt-9 UI shortcuts
ctrl_n_shortcuts = true
```

View file

@ -46,6 +46,15 @@ eval "$(atuin init zsh)"
You can then choose to bind Atuin if needed, do this after the call to init. You can then choose to bind Atuin if needed, do this after the call to init.
## <kbd>Ctrl-n</kbd> key shortcuts
macOS does not have an <kbd>Alt</kbd> key, although terminal emulators can often be configured to map the <kbd>Option</kbd> key to be used as <kbd>Alt</kbd>. *However*, remapping <kbd>Option</kbd> this way may prevent typing some characters, such as using <kbd>Option-3</kbd> to type `#` on the British English layout. For such a scenario, set the `ctrl_n_shortcuts` option to `true` in your config file to replace <kbd>Alt-0</kbd> to <kbd>Alt-9</kbd> shortcuts with <kbd>Ctrl-0</kbd> to <kbd>Ctrl-9</kbd> instead:
```
# Use Ctrl-0 .. Ctrl-9 instead of Alt-0 .. Alt-9 UI shortcuts
ctrl_n_shortcuts = true
```
## zsh ## zsh
If you'd like to customize your bindings further, it's possible to do so with custom shell config: If you'd like to customize your bindings further, it's possible to do so with custom shell config: