Skip to content

Commit

Permalink
adding grep in files for vi
Browse files Browse the repository at this point in the history
  • Loading branch information
yerlaser committed Oct 18, 2023
1 parent 1059c78 commit 47ac18f
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions configs/nushell/files.nu
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,6 @@ export def tree (
broot $args
}

# Open files with vi possibly filtering files
export def vi (
--filter_pattern (-f): string # Search pattern
--exclude_pattern (-x): string # Exclude pattern
--max_number (-m): int = 13 # Max number of items to open
...paths # Paths to open or search (if only one or and not a file)
) {
if ($filter_pattern | is-empty) and ($exclude_pattern | is-empty) {
if ($paths | is-empty) {
^hx -c $'/tmp/config($env.THEME).toml'
} else if ($paths | length) > 1 {
^hx -c $'/tmp/config($env.THEME).toml' $paths
} else if ($paths | get 0 | path type) == dir or (
($paths | get 0 | path type) == symlink and (ls -l $"($paths | get 0)*" | get target) == dir
) {
l -m ($max_number) ($paths | get 0) -e
} else {
^hx -c $'/tmp/config($env.THEME).toml' $paths
}
} else if ($paths | length) > 1 {
print "Error multiple paths with search pattern are not allowed"
} else {
if ($paths | is-empty) {
l -m ($max_number) -f $filter_pattern -x $exclude_pattern -e
} else {
l -m ($max_number) -f $filter_pattern -x $exclude_pattern ($paths | get 0) -e
}
}
}

# Open files previously listed with l
export def e (
--max_number (-m): int = 13 # Max number of items to open
Expand Down Expand Up @@ -106,3 +76,34 @@ export def cat (
) {
open -r $path | lines
}

# Open files with vi possibly filtering files
export def vi (
--filter_pattern (-f): string # Search pattern
--exclude_pattern (-x): string # Exclude pattern
--grep_pattern (-g): string # Pattern to grep inside files
--max_number (-m): int = 13 # Max number of items to open
...paths # Paths to open or search (if only one or and not a file)
) {
if ($filter_pattern | is-empty) and ($exclude_pattern | is-empty) and ($grep_pattern | is-empty) {
if ($paths | is-empty) {
^hx -c $'/tmp/config($env.THEME).toml'
} else if ($paths | length) > 1 {
^hx -c $'/tmp/config($env.THEME).toml' $paths
} else if ($paths | get 0 | path type) == dir or (
($paths | get 0 | path type) == symlink and (ls -l $"($paths | get 0)*" | get target) == dir
) {
l -m ($max_number) ($paths | get 0) -e
} else {
^hx -c $'/tmp/config($env.THEME).toml' $paths
}
} else if ($paths | length) > 1 {
print "Error multiple paths with search pattern are not allowed"
} else {
if ($paths | is-empty) {
l -m ($max_number) -f $filter_pattern -x $exclude_pattern -g $grep_pattern -e
} else {
l -m ($max_number) -f $filter_pattern -x $exclude_pattern -g $grep_pattern ($paths | get 0) -e
}
}
}

0 comments on commit 47ac18f

Please sign in to comment.