mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-01-24 11:29:01 +00: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:
127
dot_config/nushell/nu_scripts/modules/filesystem/bm.nu
Normal file
127
dot_config/nushell/nu_scripts/modules/filesystem/bm.nu
Normal file
@@ -0,0 +1,127 @@
|
||||
# simple bookmark module
|
||||
|
||||
# Prints general information about bm.
|
||||
export def main [] {
|
||||
print -n (help bm)
|
||||
|
||||
print (
|
||||
[
|
||||
$"(ansi green)Environment(ansi reset):"
|
||||
$" (ansi cyan)BM_PATH(ansi reset) - path to save bookmarks to with ('add' | nu-highlight). Alternatively searches for (ansi cyan)XDG_DATA_HOME(ansi reset) or (ansi cyan)~/.local/share/(ansi reset)"
|
||||
] |
|
||||
str join "\n" |
|
||||
nu-highlight
|
||||
)
|
||||
}
|
||||
|
||||
# List all bookmarked paths
|
||||
export def list [] {
|
||||
let bm_path = (get_path)
|
||||
|
||||
if (not ($bm_path | path exists)) {
|
||||
[] | save $bm_path
|
||||
}
|
||||
open ($bm_path)
|
||||
}
|
||||
|
||||
def os_home [] {
|
||||
if ($nu.os-info.name == "windows" ) {
|
||||
($env.USERPROFILE)
|
||||
} else {
|
||||
($env.HOME)
|
||||
}
|
||||
}
|
||||
|
||||
def get_path [] {
|
||||
$env.BM_PATH? |
|
||||
default (
|
||||
$env.XDG_DATA_HOME? |
|
||||
default (
|
||||
if $nu.os-info.name == windows {
|
||||
($env.USERPROFILE? | path join "bm")
|
||||
} else {
|
||||
($env.HOME? | path join ".local" "share")
|
||||
}
|
||||
)
|
||||
) |
|
||||
if (not ($in | path exists)) {
|
||||
mkdir $in
|
||||
$in
|
||||
} else {
|
||||
$in
|
||||
}|
|
||||
path join "bookmarks.nuon"
|
||||
}
|
||||
|
||||
def save_path [] {
|
||||
$in |
|
||||
update path { str replace (os_home) '~' } |
|
||||
save -f (get_path)
|
||||
}
|
||||
|
||||
# Reset the bookmarks
|
||||
export def reset [] {
|
||||
list |
|
||||
where name == "prev" |
|
||||
save -f (get_path)
|
||||
}
|
||||
|
||||
# Add a new bookmark with an optional name
|
||||
export def add [
|
||||
pth: path # Path to bookmark to.
|
||||
name?: string # Optional name to give to it
|
||||
] {
|
||||
if (($pth | path type) == "dir") and ($pth | path exists) {
|
||||
list |
|
||||
append {name: ($name), path: ($pth)} |
|
||||
save_path
|
||||
}
|
||||
}
|
||||
|
||||
# remove one or more bookmarks
|
||||
export def remove [] {
|
||||
let rm_these = (
|
||||
list |
|
||||
where name != "prev" |
|
||||
input list -m
|
||||
)
|
||||
|
||||
list | where {|it|
|
||||
not $it in $rm_these
|
||||
} |
|
||||
print
|
||||
|
||||
}
|
||||
|
||||
def marks [] {
|
||||
list | each {|it|
|
||||
{
|
||||
value: $it.path,
|
||||
description: $it.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Goto your bookmark
|
||||
export def --env goto [
|
||||
pth: path@marks # Path to "go to"
|
||||
] {
|
||||
let prev = $env.PWD
|
||||
cd $pth
|
||||
change_prev $prev
|
||||
}
|
||||
|
||||
# Experimental use of `input` instead of completion
|
||||
export def --env goto_alternative [] {
|
||||
let prev = $env.PWD
|
||||
list | input list -f | cd $in.path
|
||||
change_prev $prev
|
||||
}
|
||||
|
||||
def change_prev [new_path: path] {
|
||||
( list |
|
||||
where name != "prev"
|
||||
) |
|
||||
append {name: prev, path: $new_path} |
|
||||
save_path
|
||||
}
|
||||
64
dot_config/nushell/nu_scripts/modules/filesystem/expand.nu
Normal file
64
dot_config/nushell/nu_scripts/modules/filesystem/expand.nu
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
# A bash like quick string manipulation script
|
||||
# the script works by creating a list from brace contents, separated by a brace.
|
||||
|
||||
# Expand the given string into a list on braces like bashes brace expansion
|
||||
export def main [
|
||||
input: string # the string to expand.
|
||||
] {
|
||||
listify $input
|
||||
}
|
||||
|
||||
def listify [lst] {
|
||||
try {
|
||||
($lst
|
||||
| parse -r '(?P<left>.*)(?<!\\){(?P<list>.*)(?<!\\)}(?P<right>.*)'
|
||||
| get 0
|
||||
| upsert list { |l|
|
||||
$l.list
|
||||
| split row ","
|
||||
| str trim
|
||||
}
|
||||
| each { |it|
|
||||
$it.list
|
||||
| each { |l|
|
||||
listify $"($it.left)($l)($it.right)"
|
||||
}})
|
||||
| flatten
|
||||
} catch {
|
||||
$lst
|
||||
}
|
||||
}
|
||||
|
||||
export def help [] {
|
||||
print -n ( main -h )
|
||||
|
||||
print (
|
||||
[
|
||||
$"(ansi green)Examples(ansi reset):"
|
||||
$" > (ansi light_green)expand (ansi green)a/{b,c}/d(ansi reset)"
|
||||
$"╭───┬───────╮\n│ 0 │ a/b/d │\n│ 1 │ a/c/d │\n╰───┴───────╯"
|
||||
$" > (ansi light_green)expand (ansi green)\"my {beautiful,ugly} duckling\"(ansi reset)"
|
||||
$"╭───┬────────────────────────╮\n│ 0 │ my beautiful duckling │\n│ 1 │ my ugly duckling │\n╰───┴────────────────────────╯"
|
||||
$" > (ansi light_green)expand (ansi green).config/nushell/config.nu{,on}(ansi reset)"
|
||||
$"╭───┬─────────────────────────────╮\n│ 0 │ .config/nushell/config.nu │\n│ 1 │ .config/nushell/config.nuon │\n╰───┴─────────────────────────────╯"
|
||||
$" > (ansi light_green)expand (ansi green)a/{b,c}/{d,e,f,g} (ansi reset)(ansi purple)|(ansi reset)(ansi light_green) each(ansi reset) (ansi light_green){ |d| (ansi reset)(ansi light_green) mkdir(ansi reset) (ansi purple)$d (ansi reset)(ansi light_green)}(ansi reset);(ansi light_green)tree(ansi reset)"
|
||||
$".
|
||||
`-- a
|
||||
|-- b
|
||||
| |-- d
|
||||
| |-- e
|
||||
| |-- f
|
||||
| `-- g
|
||||
`-- c
|
||||
|-- d
|
||||
|-- e
|
||||
|-- f
|
||||
`-- g
|
||||
|
||||
12 directories, 0 files"
|
||||
] |
|
||||
str join "\n" |
|
||||
nu-highlight
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user