mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-03-29 16:02:55 +01:00
Changed . token to _dot
This change allows the dotfiles to work with chezmoi (e.g: on windows) and improves grepability with neovim/telescope
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
use ../conversions/into.nu *
|
||||
use ./select-ranges.nu *
|
||||
|
||||
export def main [ ...ranges ] {
|
||||
let indices = (
|
||||
$ranges
|
||||
| reduce -f [] {|range,indices|
|
||||
$indices ++ ($range | into list)
|
||||
}
|
||||
)
|
||||
|
||||
$in | columns
|
||||
| select ranges $indices
|
||||
| get item
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export use ./select-ranges.nu *
|
||||
export use ./reject-ranges.nu *
|
||||
export use ./select-column-ranges.nu *
|
||||
export use ./reject-column-ranges.nu *
|
||||
export use ./row-indices.nu *
|
||||
export use ./col-indices.nu *
|
||||
@@ -0,0 +1,13 @@
|
||||
use ./col-indices.nu *
|
||||
|
||||
# Relect a range of columns by their indices
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# ls | reject column-ranges 0 4 5 | first 3
|
||||
export def "reject column-ranges" [
|
||||
...ranges
|
||||
] {
|
||||
let column_selector = ($in | col-indices ...$ranges)
|
||||
$in | reject ...$column_selector
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use ./row-indices.nu *
|
||||
|
||||
# Rejects one or more rows while keeping
|
||||
# the original indices.
|
||||
#
|
||||
# Example - Rejects the first, fifth, and
|
||||
# sixth rows from the table:
|
||||
#
|
||||
# ls / | reject ranges 0 4..5
|
||||
export def "reject ranges" [ ...ranges ] {
|
||||
enumerate
|
||||
| flatten
|
||||
| reject ...(row-indices ...$ranges)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
use ../conversions/into.nu *
|
||||
|
||||
# Return a list of indices
|
||||
# for the provided ranges or indices.
|
||||
# Primarily used as a helper for
|
||||
# "select ranges" et. al.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# row-indices 0 2..5 7..8
|
||||
# # => ╭───┬───╮
|
||||
# # => │ 0 │ 0 │
|
||||
# # => │ 1 │ 2 │
|
||||
# # => │ 2 │ 3 │
|
||||
# # => │ 3 │ 4 │
|
||||
# # => │ 4 │ 5 │
|
||||
# # => │ 5 │ 7 │
|
||||
# # => │ 6 │ 8 │
|
||||
# # => ╰───┴───╯
|
||||
export def main [ ...ranges ] {
|
||||
$ranges
|
||||
| reduce -f [] {|range,indices|
|
||||
$indices ++ ($range | into list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
use ./col-indices.nu *
|
||||
|
||||
# Select a range of columns by their indices
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# ls -l | select column-ranges 0 10..12 | first 3
|
||||
# # => ╭───┬────────────────────┬──────────────┬─────────────┬──────────────╮
|
||||
# # => │ # │ name │ created │ accessed │ modified │
|
||||
# # => ├───┼────────────────────┼──────────────┼─────────────┼──────────────┤
|
||||
# # => │ 0 │ CITATION.cff │ 3 months ago │ 4 hours ago │ 3 months ago │
|
||||
# # => │ 1 │ CODE_OF_CONDUCT.md │ 7 months ago │ 4 hours ago │ 7 months ago │
|
||||
# # => │ 2 │ CONTRIBUTING.md │ 3 months ago │ 4 hours ago │ 3 months ago │
|
||||
# # => ╰───┴────────────────────┴──────────────┴─────────────┴──────────────╯
|
||||
export def "select column-ranges" [
|
||||
...ranges
|
||||
] {
|
||||
let column_selector = ($in | col-indices ...$ranges)
|
||||
$in | select ...$column_selector
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
use ./row-indices.nu *
|
||||
|
||||
# Selects one or more rows while keeping
|
||||
# the original indices.
|
||||
#
|
||||
# Example - Selects the first, fifth, and
|
||||
# sixth rows from the table:
|
||||
#
|
||||
# ls / | select ranges 0 4..5
|
||||
#
|
||||
# Example - Select the 5th row:
|
||||
#
|
||||
# ls / | select 5
|
||||
#
|
||||
# Example - Select the 4th row.
|
||||
# Note that the difference beteen this
|
||||
# and `select 3` is that the index (#)
|
||||
# column shows the *original* (pre-select)
|
||||
# position in the table.
|
||||
#
|
||||
# ls | select ranges 3
|
||||
export def "select ranges" [ ...ranges ] {
|
||||
enumerate
|
||||
| flatten
|
||||
| select ...(row-indices ...$ranges)
|
||||
}
|
||||
Reference in New Issue
Block a user