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
- [ ] `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; [
age
fd
nushell
sqlite

47
mod.nu
View File

@@ -178,11 +178,11 @@ export def "envr init" [
priv_key: $identity
pub_key: $'($identity).pub'
# TODO: scan settings
# scan: {
# matcher: '\.env'
# exclude: '*.envrc'
# include: '~'
# }
scan: {
matcher: '\.env'
exclude: '*.envrc'
include: '~'
}
} | tee {
save $source;
open db
@@ -217,9 +217,42 @@ export def "envr sync" [] {
'TODO: Need to implement'
}
# Search for .env files
# Search for .env files and select ones to back up.
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