Skip to content

Commit

Permalink
vi without fd
Browse files Browse the repository at this point in the history
  • Loading branch information
yerlaser committed Sep 26, 2023
1 parent 8a3f81f commit 0e97d90
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions configs/nushell/files.nu
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,31 @@ export def tree (
broot $args
}

# Open all files with default editor
# Open files with vi possibly filtering files
export def vi (
--exclude (-x): string # Exclude string
--exclude_pattern (-x): string # Exclude pattern
--filter_pattern (-f): string # Search pattern
...paths # Paths to open or search (if only one or and not a file)
) {
let $paths = if ($paths | is-empty) {['.']} else {$paths}
let $filter_pattern = if ($filter_pattern | is-empty) {''} else {$filter_pattern}
let files = if ($exclude | is-empty) {
(do {fd -t f -t l -F $filter_pattern $paths} | complete | get stdout | lines)
} else {
(do {fd -E $'*($exclude)*' -t f -t l -F $filter_pattern $paths} | complete | get stdout | lines)
}
if ($files | is-empty) or (($files | length) > 13) {
let paths = if ($paths | is-empty) { ['.'] } else { $paths }
let paths = if ($paths | get 0 | path type) == symlink { (ls -l $"($paths | get 0)*" | get target) } else { $paths }
if ($paths | get 0) == '.' and ($filter_pattern | is-empty) {
^hx -c $'/tmp/config($env.THEME).toml'
} else if ($paths | length) > 1 {
^hx -c $'/tmp/config($env.THEME).toml' $paths
} else if not (($paths | get 0 | path type) == dir) {
^hx -c $'/tmp/config($env.THEME).toml' $paths
} else {
^hx -c $'/tmp/config($env.THEME).toml' $files
let path = if ($paths | get 0) == '.' { '**/*' } else { $"($paths | get 0 | str trim -r -c '/')/**/*" }
let expression = if ($filter_pattern | is-empty) { $path } else { $"($path)\(?i\)($filter_pattern)*" }
let excludes = ['**/node_modules/**' '**/target/**' '**/.git/**' '**/zig-out/**' '**/zig-cache/**' '**/.*' '**/.*/**']
let excludes = if ($exclude_pattern | is-empty) { $excludes } else { $excludes | append $"**/*\(?i\)($exclude_pattern)*" }
let files = glob -D $expression -n $excludes
if ($files | is-empty) or (($files | length) > 13) {
^hx -c $'/tmp/config($env.THEME).toml' $paths
} else {
^hx -c $'/tmp/config($env.THEME).toml' $files
}
}
}

Expand Down

0 comments on commit 0e97d90

Please sign in to comment.