diff --git a/CHANGELOG.md b/CHANGELOG.md index 271cfcfe16..c432c36a57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ this release has no changes to `0.26.0` but provides windows binaries that were * support `core.commitChar` filtering [[@concelare](https://github.com/concelare)] ([#2136](https://github.com/extrawurst/gitui/issues/2136)) * allow reset in branch popup ([#2170](https://github.com/extrawurst/gitui/issues/2170)) * respect configuration for remote when pushing [[@cruessler](https://github.com/cruessler)] ([#2156](https://github.com/extrawurst/gitui/issues/2156)) +* support global options [[@remique](https://github.com/remique)] ([#2140](https://github.com/extrawurst/gitui/issues/2140)) ### Changed * Make info and error message popups scrollable [[@MichaelAug](https://github.com/MichaelAug)] ([#1138](https://github.com/extrawurst/gitui/issues/1138)) diff --git a/GLOBAL_OPTIONS.md b/GLOBAL_OPTIONS.md new file mode 100644 index 0000000000..fd8503f737 --- /dev/null +++ b/GLOBAL_OPTIONS.md @@ -0,0 +1,32 @@ +# Global options + +You can set global options that will take effect over the entire system for GitUI. Note however, that each time GitUI closes, it saves a local config file (`./.git/gitui.ron`) that has a higher order precedence. Meaning, if you had changed global config while already having local file for given repository, the changes will not be visible. + +The reason behind this decision is local file has additional fields saved which facilitates GitUI for a specific repository (eg. `tab` which allows to open up GitUI in the last tab it was closed with). + +The precedence of fetching the options is: + +1. Use **local** options file. _If not found then:_ +2. Use **global** options file. _If not found then:_ +3. Use default values. + +To set up global options create `gitui.ron` file: + +``` +( + diff: ( + ignore_whitespace: false, + context: 3, + interhunk_lines: 2, + ), + status_show_untracked: None, +) +``` + +The options file format based on the [Ron file format](https://github.com/ron-rs/ron). +The location of the file depends on your OS: + +- `$HOME/.config/gitui/gitui.ron` (mac) +- `$XDG_CONFIG_HOME/gitui/gitui.ron` (linux using XDG) +- `$HOME/.config/gitui/gitui.ron` (linux) +- `%APPDATA%/gitui/gitui.ron` (Windows) diff --git a/README.md b/README.md index 65f3b65c16..912fbbeac1 100644 --- a/README.md +++ b/README.md @@ -267,11 +267,17 @@ However, you can customize everything to your liking: See [Themes](THEMES.md). The key bindings can be customized: See [Key Config](KEY_CONFIG.md) on how to set them to `vim`-like bindings. -## 12. Sponsoring [Top ▲](#table-of-contents) +## 12. Global options [Top ▲](#table-of-contents) + +The key bindings can be customized: See [Key Config](KEY_CONFIG.md) on how to set them to `vim`-like bindings. + +You can set Global Options: See [Global Options](GLOBAL_OPTIONS.md) on how to set it up. + +## 13. Sponsoring [Top ▲](#table-of-contents) [![github](https://img.shields.io/badge/-GitHub%20Sponsors-fafbfc?logo=GitHub%20Sponsors)](https://github.com/sponsors/extrawurst) -## 13. Inspiration [Top ▲](#table-of-contents) +## 14. Inspiration [Top ▲](#table-of-contents) - [lazygit](https://github.com/jesseduffield/lazygit) - [tig](https://github.com/jonas/tig) @@ -279,11 +285,11 @@ The key bindings can be customized: See [Key Config](KEY_CONFIG.md) on how to se - It would be nice to come up with a way to have the map view available in a terminal tool - [git-brunch](https://github.com/andys8/git-brunch) -## 14. Contributing [Top ▲](#table-of-contents) +## 15. Contributing [Top ▲](#table-of-contents) See [CONTRIBUTING.md](CONTRIBUTING.md). -## 15. Contributors [Top ▲](#table-of-contents) +## 16. Contributors [Top ▲](#table-of-contents) Thanks goes to all the contributors that help make GitUI amazing! ❤️ diff --git a/src/options.rs b/src/options.rs index db04802092..1ac9eaac54 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,3 +1,5 @@ +use crate::args::get_app_config_path; + use anyhow::Result; use asyncgit::sync::{ diff::DiffOptions, repo_dir, RepoPathRef, @@ -26,6 +28,8 @@ struct OptionsData { const COMMIT_MSG_HISTORY_LENGTH: usize = 20; +const OPTIONS_FILENAME: &str = "gitui.ron"; + #[derive(Clone)] pub struct Options { repo: RepoPathRef, @@ -144,11 +148,19 @@ impl Options { } fn read(repo: &RepoPathRef) -> Result { - let dir = Self::options_file(repo)?; + let local_file = Self::options_file(repo)?; + + let app_home = get_app_config_path()?; + let config_file = app_home.join(OPTIONS_FILENAME); + + let mut f = match File::open(local_file) { + Ok(file) => file, + Err(_) => File::open(config_file)?, + }; - let mut f = File::open(dir)?; let mut buffer = Vec::new(); f.read_to_end(&mut buffer)?; + Ok(from_bytes(&buffer)?) } @@ -167,7 +179,7 @@ impl Options { fn options_file(repo: &RepoPathRef) -> Result { let dir = repo_dir(&repo.borrow())?; - let dir = dir.join("gitui"); + let dir = dir.join(OPTIONS_FILENAME); Ok(dir) } }