mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
feat(cli): add the ability to specify a custom keybinding/symbols file via the cli (#2731)
This commit is contained in:
parent
92e3b739d7
commit
e1029b00d1
4 changed files with 58 additions and 10 deletions
|
|
@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
* add `use_selection_fg` to theme file to allow customizing selection foreground color [[@Upsylonbare](https://github.com/Upsylonbare)] ([#2515](https://github.com/gitui-org/gitui/pull/2515))
|
* add `use_selection_fg` to theme file to allow customizing selection foreground color [[@Upsylonbare](https://github.com/Upsylonbare)] ([#2515](https://github.com/gitui-org/gitui/pull/2515))
|
||||||
* add "go to line" command for the blame view [[@andrea-berling](https://github.com/andrea-berling)] ([#2262](https://github.com/extrawurst/gitui/pull/2262))
|
* add "go to line" command for the blame view [[@andrea-berling](https://github.com/andrea-berling)] ([#2262](https://github.com/extrawurst/gitui/pull/2262))
|
||||||
* add `--file` cli flag to open the files tab with the given file already selected [[@laktak](https://github.com/laktak)] ([#2510](https://github.com/gitui-org/gitui/issues/2510))
|
* add `--file` cli flag to open the files tab with the given file already selected [[@laktak](https://github.com/laktak)] ([#2510](https://github.com/gitui-org/gitui/issues/2510))
|
||||||
|
* add the ability to specify a custom keybinding/symbols file via the cli [[@0x61nas](https://github.com/0x61nas)] ([#2731](https://github.com/gitui-org/gitui/pull/2731))
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* execute git-hooks directly if possible (on *nix) else use sh instead of bash (without reading SHELL variable) [[@Joshix](https://github.com/Joshix-1)] ([#2483](https://github.com/extrawurst/gitui/pull/2483))
|
* execute git-hooks directly if possible (on *nix) else use sh instead of bash (without reading SHELL variable) [[@Joshix](https://github.com/Joshix-1)] ([#2483](https://github.com/extrawurst/gitui/pull/2483))
|
||||||
|
|
|
||||||
30
src/args.rs
30
src/args.rs
|
|
@ -20,6 +20,8 @@ const WORKDIR_FLAG_ID: &str = "workdir";
|
||||||
const FILE_FLAG_ID: &str = "file";
|
const FILE_FLAG_ID: &str = "file";
|
||||||
const GIT_DIR_FLAG_ID: &str = "directory";
|
const GIT_DIR_FLAG_ID: &str = "directory";
|
||||||
const WATCHER_FLAG_ID: &str = "watcher";
|
const WATCHER_FLAG_ID: &str = "watcher";
|
||||||
|
const KEY_BINDINGS_FLAG_ID: &str = "key_bindings";
|
||||||
|
const KEY_SYMBOLS_FLAG_ID: &str = "key_symbols";
|
||||||
const DEFAULT_THEME: &str = "theme.ron";
|
const DEFAULT_THEME: &str = "theme.ron";
|
||||||
const DEFAULT_GIT_DIR: &str = ".";
|
const DEFAULT_GIT_DIR: &str = ".";
|
||||||
|
|
||||||
|
|
@ -29,6 +31,8 @@ pub struct CliArgs {
|
||||||
pub select_file: Option<PathBuf>,
|
pub select_file: Option<PathBuf>,
|
||||||
pub repo_path: RepoPath,
|
pub repo_path: RepoPath,
|
||||||
pub notify_watcher: bool,
|
pub notify_watcher: bool,
|
||||||
|
pub key_bindings_path: Option<PathBuf>,
|
||||||
|
pub key_symbols_path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_cmdline() -> Result<CliArgs> {
|
pub fn process_cmdline() -> Result<CliArgs> {
|
||||||
|
|
@ -80,11 +84,21 @@ pub fn process_cmdline() -> Result<CliArgs> {
|
||||||
let notify_watcher: bool =
|
let notify_watcher: bool =
|
||||||
*arg_matches.get_one(WATCHER_FLAG_ID).unwrap_or(&false);
|
*arg_matches.get_one(WATCHER_FLAG_ID).unwrap_or(&false);
|
||||||
|
|
||||||
|
let key_bindings_path = arg_matches
|
||||||
|
.get_one::<String>(KEY_BINDINGS_FLAG_ID)
|
||||||
|
.map(PathBuf::from);
|
||||||
|
|
||||||
|
let key_symbols_path = arg_matches
|
||||||
|
.get_one::<String>(KEY_SYMBOLS_FLAG_ID)
|
||||||
|
.map(PathBuf::from);
|
||||||
|
|
||||||
Ok(CliArgs {
|
Ok(CliArgs {
|
||||||
theme,
|
theme,
|
||||||
select_file,
|
select_file,
|
||||||
repo_path,
|
repo_path,
|
||||||
notify_watcher,
|
notify_watcher,
|
||||||
|
key_bindings_path,
|
||||||
|
key_symbols_path,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,6 +117,22 @@ fn app() -> ClapApp {
|
||||||
|
|
||||||
{all-args}{after-help}
|
{all-args}{after-help}
|
||||||
",
|
",
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new(KEY_BINDINGS_FLAG_ID)
|
||||||
|
.help("Use a custom keybindings file")
|
||||||
|
.short('k')
|
||||||
|
.long("key-bindings")
|
||||||
|
.value_name("KEY_LIST_FILENAME")
|
||||||
|
.num_args(1),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new(KEY_SYMBOLS_FLAG_ID)
|
||||||
|
.help("Use a custom symbols file")
|
||||||
|
.short('s')
|
||||||
|
.long("key-symbols")
|
||||||
|
.value_name("KEY_SYMBOLS_FILENAME")
|
||||||
|
.num_args(1),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(THEME_FLAG_ID)
|
Arg::new(THEME_FLAG_ID)
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,21 @@ impl KeyConfig {
|
||||||
.map_or_else(|_| Ok(symbols_file), Ok)
|
.map_or_else(|_| Ok(symbols_file), Ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() -> Result<Self> {
|
pub fn init(
|
||||||
let keys = KeysList::init(Self::get_config_file()?);
|
key_bindings_path: Option<&PathBuf>,
|
||||||
let symbols = KeySymbols::init(Self::get_symbols_file()?);
|
key_symbols_path: Option<&PathBuf>,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let keys = KeysList::init(
|
||||||
|
key_bindings_path
|
||||||
|
.unwrap_or(&Self::get_config_file()?)
|
||||||
|
.clone(),
|
||||||
|
);
|
||||||
|
let symbols = KeySymbols::init(
|
||||||
|
key_symbols_path
|
||||||
|
.unwrap_or(&Self::get_symbols_file()?)
|
||||||
|
.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(Self { keys, symbols })
|
Ok(Self { keys, symbols })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,7 +197,7 @@ mod tests {
|
||||||
|
|
||||||
// testing
|
// testing
|
||||||
let result = std::panic::catch_unwind(|| {
|
let result = std::panic::catch_unwind(|| {
|
||||||
let loaded_config = KeyConfig::init().unwrap();
|
let loaded_config = KeyConfig::init(None, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
loaded_config.keys.move_down,
|
loaded_config.keys.move_down,
|
||||||
KeysList::default().move_down
|
KeysList::default().move_down
|
||||||
|
|
@ -200,7 +212,7 @@ mod tests {
|
||||||
&original_key_symbols_path,
|
&original_key_symbols_path,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let loaded_config = KeyConfig::init().unwrap();
|
let loaded_config = KeyConfig::init(None, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
loaded_config.keys.move_down,
|
loaded_config.keys.move_down,
|
||||||
KeysList::default().move_down
|
KeysList::default().move_down
|
||||||
|
|
@ -212,7 +224,7 @@ mod tests {
|
||||||
&original_key_list_path,
|
&original_key_list_path,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let loaded_config = KeyConfig::init().unwrap();
|
let loaded_config = KeyConfig::init(None, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
loaded_config.keys.move_down,
|
loaded_config.keys.move_down,
|
||||||
GituiKeyEvent::new(
|
GituiKeyEvent::new(
|
||||||
|
|
@ -223,7 +235,7 @@ mod tests {
|
||||||
assert_eq!(loaded_config.symbols.esc, "Esc");
|
assert_eq!(loaded_config.symbols.esc, "Esc");
|
||||||
|
|
||||||
fs::remove_file(&original_key_symbols_path).unwrap();
|
fs::remove_file(&original_key_symbols_path).unwrap();
|
||||||
let loaded_config = KeyConfig::init().unwrap();
|
let loaded_config = KeyConfig::init(None, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
loaded_config.keys.move_down,
|
loaded_config.keys.move_down,
|
||||||
GituiKeyEvent::new(
|
GituiKeyEvent::new(
|
||||||
|
|
|
||||||
11
src/main.rs
11
src/main.rs
|
|
@ -170,9 +170,12 @@ fn main() -> Result<()> {
|
||||||
asyncgit::register_tracing_logging();
|
asyncgit::register_tracing_logging();
|
||||||
ensure_valid_path(&cliargs.repo_path)?;
|
ensure_valid_path(&cliargs.repo_path)?;
|
||||||
|
|
||||||
let key_config = KeyConfig::init()
|
let key_config = KeyConfig::init(
|
||||||
.map_err(|e| log_eprintln!("KeyConfig loading error: {e}"))
|
cliargs.key_bindings_path.as_ref(),
|
||||||
.unwrap_or_default();
|
cliargs.key_symbols_path.as_ref(),
|
||||||
|
)
|
||||||
|
.map_err(|e| log_eprintln!("KeyConfig loading error: {e}"))
|
||||||
|
.unwrap_or_default();
|
||||||
let theme = Theme::init(&cliargs.theme);
|
let theme = Theme::init(&cliargs.theme);
|
||||||
|
|
||||||
setup_terminal()?;
|
setup_terminal()?;
|
||||||
|
|
@ -212,6 +215,8 @@ fn main() -> Result<()> {
|
||||||
select_file: None,
|
select_file: None,
|
||||||
theme: args.theme,
|
theme: args.theme,
|
||||||
notify_watcher: args.notify_watcher,
|
notify_watcher: args.notify_watcher,
|
||||||
|
key_bindings_path: args.key_bindings_path,
|
||||||
|
key_symbols_path: args.key_symbols_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue