Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Selectable menus will be available when using `kubie ctx` and `kubie ns`.
* `kubie update` will check the latest kubie version and update your local installation if needed

## Settings
You can customize kubie's behavior with the `~/.kube/kubie.yaml` file. The settings available and their defaults are
You can customize kubie's behavior with the `~/.config/kubie/config.yaml` file. The settings available and their defaults are
available below.

```yaml
Expand Down Expand Up @@ -165,7 +165,7 @@ behavior:

# Optional start and stop hooks
hooks:
# A command hook to run when a CTX is started.
# A command hook to run when a CTX is started.
# This example re-labels your terminal window
# Default: none
start_ctx: >
Expand Down
28 changes: 25 additions & 3 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::fs::File;
use std::fs::{self, File};
use std::io::BufReader;
use std::path::{Path, PathBuf};

Expand All @@ -14,13 +14,23 @@ lazy_static! {
.to_str()
.expect("home directory contains non unicode characters")
.to_string();
static ref CONFIG_DIR: String = dirs::config_dir()
.expect("could not get config_dir")
.to_str()
.expect("config_dir contains non unicode characters")
.to_string();
}

#[inline]
fn home_dir() -> &'static str {
&HOME_DIR
}

#[inline]
fn config_dir() -> &'static str {
&CONFIG_DIR
}

pub fn expanduser(path: &str) -> String {
if let Some(stripped) = path.strip_prefix("~/") {
format!("{}/{}", home_dir(), stripped)
Expand All @@ -45,7 +55,18 @@ pub struct Settings {

impl Settings {
pub fn path() -> String {
format!("{}/.kube/kubie.yaml", home_dir())
let legacy_path = format!("{}/.kube/kubie.yaml", home_dir());
let xdg_dir = format!("{}/kubie", config_dir());
let xdg_path = format!("{}/config.yaml", xdg_dir);

if Path::new(&legacy_path).exists() {
legacy_path
} else if !Path::new(&xdg_dir).is_dir() {
fs::create_dir_all(xdg_dir).expect("could not create config directory");
xdg_path
} else {
xdg_path
}
}

pub fn load() -> Result<Settings> {
Expand All @@ -60,7 +81,8 @@ impl Settings {
Settings::default()
};

// Very important to exclude kubie's own config file ~/.kube/kubie.yaml from the results.
// Very important to exclude kubie's own config file from the results
// it is ~/.config/kubie/config.yaml by default
settings.configs.exclude.push(settings_path_str);
Ok(settings)
}
Expand Down