From 30bb3b49f976fb1a83293f0fc0b56ceebd6ee184 Mon Sep 17 00:00:00 2001 From: Uttarayan Date: Fri, 13 Oct 2023 18:21:22 +0530 Subject: [PATCH] [fix] Update nushell files --- config/nushell/conf.d/cargo.nu | 12 ++ config/nushell/{scripts => conf.d}/conda.nu | 0 config/nushell/config.nu | 199 ++++---------------- config/nushell/env.nu | 16 +- config/tmux/tmux.conf | 3 +- 5 files changed, 59 insertions(+), 171 deletions(-) create mode 100644 config/nushell/conf.d/cargo.nu rename config/nushell/{scripts => conf.d}/conda.nu (100%) diff --git a/config/nushell/conf.d/cargo.nu b/config/nushell/conf.d/cargo.nu new file mode 100644 index 00000000..05e107b5 --- /dev/null +++ b/config/nushell/conf.d/cargo.nu @@ -0,0 +1,12 @@ +def "cargo search" [ query: string, --limit=10] { + ^cargo search $query --limit $limit + | lines + | each { + |line| if ($line | str contains "#") { + $line | parse --regex '(?P.+) = "(?P.+)" +# (?P.+)' + } else { + $line | parse --regex '(?P.+) = "(?P.+)"' + } + } + | flatten +} diff --git a/config/nushell/scripts/conda.nu b/config/nushell/conf.d/conda.nu similarity index 100% rename from config/nushell/scripts/conda.nu rename to config/nushell/conf.d/conda.nu diff --git a/config/nushell/config.nu b/config/nushell/config.nu index 1ef054c5..97651834 100644 --- a/config/nushell/config.nu +++ b/config/nushell/config.nu @@ -1,130 +1,37 @@ # Nushell Config File -module completions { - # Custom completions for external commands (those outside of Nushell) - # Each completions has two parts: the form of the external command, including its flags and parameters - # and a helper command that knows how to complete values for those flags and parameters - # - # This is a simplified version of completions for git branches and git remotes - def "nu-complete git branches" [] { - ^git branch | lines | each { |line| $line | str replace '[\*\+] ' '' | str trim } - } - - def "nu-complete git remotes" [] { - ^git remote | lines | each { |line| $line | str trim } - } - - # Download objects and refs from another repository - export extern "git fetch" [ - repository?: string@"nu-complete git remotes" # name of the repository to fetch - branch?: string@"nu-complete git branches" # name of the branch to fetch - --all # Fetch all remotes - --append(-a) # Append ref names and object names to .git/FETCH_HEAD - --atomic # Use an atomic transaction to update local refs. - --depth: int # Limit fetching to n commits from the tip - --deepen: int # Limit fetching to n commits from the current shallow boundary - --shallow-since: string # Deepen or shorten the history by date - --shallow-exclude: string # Deepen or shorten the history by branch/tag - --unshallow # Fetch all available history - --update-shallow # Update .git/shallow to accept new refs - --negotiation-tip: string # Specify which commit/glob to report while fetching - --negotiate-only # Do not fetch, only print common ancestors - --dry-run # Show what would be done - --write-fetch-head # Write fetched refs in FETCH_HEAD (default) - --no-write-fetch-head # Do not write FETCH_HEAD - --force(-f) # Always update the local branch - --keep(-k) # Keep downloaded pack - --multiple # Allow several arguments to be specified - --auto-maintenance # Run 'git maintenance run --auto' at the end (default) - --no-auto-maintenance # Don't run 'git maintenance' at the end - --auto-gc # Run 'git maintenance run --auto' at the end (default) - --no-auto-gc # Don't run 'git maintenance' at the end - --write-commit-graph # Write a commit-graph after fetching - --no-write-commit-graph # Don't write a commit-graph after fetching - --prefetch # Place all refs into the refs/prefetch/ namespace - --prune(-p) # Remove obsolete remote-tracking references - --prune-tags(-P) # Remove any local tags that do not exist on the remote - --no-tags(-n) # Disable automatic tag following - --refmap: string # Use this refspec to map the refs to remote-tracking branches - --tags(-t) # Fetch all tags - --recurse-submodules: string # Fetch new commits of populated submodules (yes/on-demand/no) - --jobs(-j): int # Number of parallel children - --no-recurse-submodules # Disable recursive fetching of submodules - --set-upstream # Add upstream (tracking) reference - --submodule-prefix: string # Prepend to paths printed in informative messages - --upload-pack: string # Non-default path for remote command - --quiet(-q) # Silence internally used git commands - --verbose(-v) # Be verbose - --progress # Report progress on stderr - --server-option(-o): string # Pass options for the server to handle - --show-forced-updates # Check if a branch is force-updated - --no-show-forced-updates # Don't check if a branch is force-updated - -4 # Use IPv4 addresses, ignore IPv6 addresses - -6 # Use IPv6 addresses, ignore IPv4 addresses - --help # Display the help message for this command - ] - - # Check out git branches and files - export extern "git checkout" [ - ...targets: string@"nu-complete git branches" # name of the branch or files to checkout - --conflict: string # conflict style (merge or diff3) - --detach(-d) # detach HEAD at named commit - --force(-f) # force checkout (throw away local modifications) - --guess # second guess 'git checkout ' (default) - --ignore-other-worktrees # do not check if another worktree is holding the given ref - --ignore-skip-worktree-bits # do not limit pathspecs to sparse entries only - --merge(-m) # perform a 3-way merge with the new branch - --orphan: string # new unparented branch - --ours(-2) # checkout our version for unmerged files - --overlay # use overlay mode (default) - --overwrite-ignore # update ignored files (default) - --patch(-p) # select hunks interactively - --pathspec-from-file: string # read pathspec from file - --progress # force progress reporting - --quiet(-q) # suppress progress reporting - --recurse-submodules: string # control recursive updating of submodules - --theirs(-3) # checkout their version for unmerged files - --track(-t) # set upstream info for new branch - -b: string # create and checkout a new branch - -B: string # create/reset and checkout a branch - -l # create reflog for new branch - --help # Display the help message for this command - ] - - # Push changes - export extern "git push" [ - remote?: string@"nu-complete git remotes", # the name of the remote - ...refs: string@"nu-complete git branches" # the branch / refspec - --all # push all refs - --atomic # request atomic transaction on remote side - --delete(-d) # delete refs - --dry-run(-n) # dry run - --exec: string # receive pack program - --follow-tags # push missing but relevant tags - --force(-f) # force updates - --ipv4(-4) # use IPv4 addresses only - --ipv6(-6) # use IPv6 addresses only - --mirror # mirror all refs - --no-verify # bypass pre-push hook - --porcelain # machine-readable output - --progress # force progress reporting - --prune # prune locally removed refs - --push-option(-o): string # option to transmit - --quiet(-q) # be more quiet - --receive-pack: string # receive pack program - --recurse-submodules: string # control recursive pushing of submodules - --repo: string # repository - --set-upstream(-u) # set upstream for git pull/status - --signed: string # GPG sign the push - --tags # push tags (can't be used with --all or --mirror) - --thin # use thin pack - --verbose(-v) # be more verbose - --help # Display the help message for this command - ] +let fish_completer = {|spans| + fish --command $'complete "--do-complete=($spans | str join " ")"' + | $"value(char tab)description(char newline)" + $in + | from tsv --flexible --no-infer } -# Get just the extern definitions without the custom completion commands -use completions * +let carapace_completer = {|spans: list| + carapace $spans.0 nushell $spans + | from json + | if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null } +} + +# This completer will use carapace by default +let external_completer = {|spans| + let expanded_alias = scope aliases + | where name == $spans.0 + | get -i 0.expansion + + let spans = if $expanded_alias != null { + $spans + | skip 1 + | prepend ($expanded_alias | split row ' ') + } else { + $spans + } + + match $spans.0 { + nu => $fish_completer + git => $fish_completer + _ => $fish_completer + } | do $in $spans +} # For more information on themes, see # https://www.nushell.sh/book/coloring_and_theming.html @@ -389,7 +296,7 @@ $env.config = { external: { enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options - completer: null # check 'carapace_completer' above as an example + completer: $external_completer } } filesize: { @@ -652,51 +559,9 @@ $env.config = { ] } -let fish_completer = {|spans| - fish --command $'complete "--do-complete=($spans | str join " ")"' - | $"value(char tab)description(char newline)" + $in - | from tsv --flexible --no-infer -} - -let carapace_completer = {|spans: list| - carapace $spans.0 nushell $spans - | from json - | if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null } -} - -# This completer will use carapace by default -let external_completer = {|spans| - let expanded_alias = scope aliases - | where name == $spans.0 - | get -i 0.expansion - - let spans = if $expanded_alias != null { - $spans - | skip 1 - | prepend ($expanded_alias | split row ' ') - } else { - $spans - } - - match $spans.0 { - nu => $fish_completer - git => $fish_completer - _ => $fish_completer - } | do $in $spans -} - -$env.config = { - # ... - completions: { - external: { - enable: true - completer: $external_completer - } - } - # ... -} source starship.nu source zoxide.nu source alias.nu +source cargo.nu use conda.nu diff --git a/config/nushell/env.nu b/config/nushell/env.nu index 31837ad4..2104ce3b 100644 --- a/config/nushell/env.nu +++ b/config/nushell/env.nu @@ -63,8 +63,18 @@ load-env (fnm env --shell bash | lines | str replace 'export ' '' | str replace # To add entries to PATH (on Windows you might use Path), you can use the following pattern: # $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path') + # macOS ARM64 (Apple Silicon) -$env.PATH = ($env.PATH | split row (char esep) | prepend '/opt/homebrew/bin') -$env.PATH = ($env.PATH | prepend $"($env.FNM_MULTISHELL_PATH)/bin") +let os = (sys | get host.long_os_version) +if ($os | str contains MacOS) { + $env.PATH = ($env.PATH | split row (char esep) | prepend '/opt/homebrew/bin') +} # Linux -# $env.PATH = ($env.PATH | split row (char esep) | prepend '/home/linuxbrew/.linuxbrew/bin') +if ($os | str contains Linux) { + $env.PATH = ($env.PATH | split row (char esep) | prepend '/home/linuxbrew/.linuxbrew/bin') +} + +$env.PATH = ($env.PATH | prepend $"($env.FNM_MULTISHELL_PATH)/bin") +$env.PATH = ($env.PATH | prepend $"($env.HOME)/local/bin") +$env.EDITOR = "nvim" +$env.VISUAL = "nvim" diff --git a/config/tmux/tmux.conf b/config/tmux/tmux.conf index 29877a04..9b80ebf9 100644 --- a/config/tmux/tmux.conf +++ b/config/tmux/tmux.conf @@ -30,7 +30,7 @@ set -g @nightowl-show-weather false run -b '~/.config/tmux/plugins/tpm/tpm' # if on macos use /opt/homebrew/bin/fish -if-shell "[ -f /usr/bin/fish ]" "set -g default-shell '/usr/bin/fish'" +if-shell "[ -f /usr/bin/nu ]" "set -g default-shell '/usr/bin/nu'" if-shell "[ -f /opt/homebrew/bin/fish ]" "set -g default-shell '/opt/homebrew/bin/fish'" # if-shell "[ -f /opt/homebrew/bin/nu ]" "set -g default-shell '/opt/homebrew/bin/nu'" @@ -70,3 +70,4 @@ bind o set status bind-key -n C-\\ run-shell '~/.config/tmux/scratch' if-shell 'uname | grep -q Darwin' { set -s copy-command 'pbcopy' } +if-shell 'uname | grep -q Linux' { set -s copy-command 'wl-copy' }