feat: Implemented scan.

This commit is contained in:
2025-10-28 16:31:26 -04:00
parent 6597d987f9
commit 697968e410
3 changed files with 42 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
## TODOS ## TODOS
- [ ] `envr sync` - Restore missing .env files, and update backed up ones. - [ ] `envr sync` - Restore missing .env files, and update backed up ones.
- [ ] `envr scan` - Search for missing / moved .env files. - [x] `envr scan` - Search for missing / moved .env files.

View File

@@ -70,6 +70,7 @@
{ {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
age age
fd
nushell nushell
sqlite sqlite

47
mod.nu
View File

@@ -178,11 +178,11 @@ export def "envr init" [
priv_key: $identity priv_key: $identity
pub_key: $'($identity).pub' pub_key: $'($identity).pub'
# TODO: scan settings # TODO: scan settings
# scan: { scan: {
# matcher: '\.env' matcher: '\.env'
# exclude: '*.envrc' exclude: '*.envrc'
# include: '~' include: '~'
# } }
} | tee { } | tee {
save $source; save $source;
open db open db
@@ -217,9 +217,42 @@ export def "envr sync" [] {
'TODO: Need to implement' 'TODO: Need to implement'
} }
# Search for .env files # Search for .env files and select ones to back up.
export def "envr scan" [] { export def "envr scan" [] {
'TODO:' let config = (envr config show).scan;
let ignored_env_files = (
find env-files $config.matcher $config.exclude $config.include
);
let tracked_file_paths = (files).path;
let scanned = $ignored_env_files | where { |it|
not ($it in $tracked_file_paths)
}
(
$scanned
| input list -m "Select files to back up"
| each { envr backup $in }
)
}
# Search for hidden env files
def "find env-files" [
match: string = '\.env'
exclude: string = '*.envrc'
search: string = '~/'
]: nothing -> list<path> {
let search = ($search | path expand);
let unignored = (fd -a $match -E $exclude -H $search | lines)
let all = (fd -a $match -E $exclude -HI $search | lines)
let ignored = $all | where { |it|
not ($it in $unignored)
}
$ignored | sort
} }
# Edit your config # Edit your config