You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nu-scripts/lib/config.nu

27 lines
561 B
Plaintext

# reads a config file
export def read_file [app: string, filename = "config.toml"] {
get_path $app | path join $filename | open
}
# returns the path to an apps config dir
export def get_path [app: string] {
let home = $env.HOME?
if $home == null {
"/etc" | path join $app
}
let local = ( $home | path join ".config" | path join $app )
if ( $local | path exists ) {
$local
} else {
let etc_cfg = ( "/etc" | path join $app )
if ( $etc_cfg | path exists ) {
$etc_cfg
} else {
mkdir $local
$local
}
}
}