Add config library
parent
5621b4733c
commit
e8400a31d9
@ -0,0 +1,22 @@
|
||||
# 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 local = ( $env.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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue