mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-03-23 12:52:48 +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:
@@ -0,0 +1,19 @@
|
||||
# cool oneliners
|
||||
|
||||
Capturing oneliners to and from the nushell community.
|
||||
|
||||
Consider these a living library.
|
||||
Or an ongoing story of how people actually use `nu`.
|
||||
|
||||
## Naming and script requirements
|
||||
|
||||
- the filename should be an abbreviation of the general topic of the script
|
||||
For example:
|
||||
|
||||
```sh
|
||||
git_batch_extract.nu
|
||||
```
|
||||
|
||||
- the script should have two lines
|
||||
- the first line should be a comment describing the script's purpose
|
||||
- the second line should be the cool oneliner
|
||||
@@ -0,0 +1,6 @@
|
||||
[
|
||||
["cero", "zero"],
|
||||
["uno", "one"],
|
||||
["dos", "two"],
|
||||
["tres", "three"]
|
||||
]
|
||||
@@ -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<name>.+) = "(?P<version>.+)" +# (?P<description>.+)'
|
||||
} else {
|
||||
$line | parse --regex '(?P<name>.+) = "(?P<version>.+)"'
|
||||
}
|
||||
}
|
||||
| flatten
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/nu
|
||||
|
||||
# I actually use it as a part of my startup, so I am not really sure how to pack it, yet I wouldd like to contribute
|
||||
#-------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# How to use?
|
||||
#-------------------------------------------------
|
||||
#1) Add desired paths to the cdpath variable
|
||||
#2) Use in your shell: $c [directory]
|
||||
#2.5) You *have to* use an argument. If you wish to simply $cd, use $cd command.
|
||||
#3) If the path exists, you will cd into the first match found (the command is iterating over the list in the correct order,
|
||||
# i.e. first element is being iterated overin the first place)
|
||||
#3.5) But if path does not exist, you will receive a proper echo.
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
#Written by skelly37
|
||||
#------------------------
|
||||
|
||||
# startup = [
|
||||
# "let cdpath = [. /place/your ~/cdpath/here ]",
|
||||
# "def c [dir] { let wd = (pwd); for element in $cdpath {if (pwd) == $wd {cd $element; for directory in (ls -a | select name type | each { if $it.type == Dir {echo $it.name} {} } ) {if $dir == $directory {cd $dir} {}}; if (pwd) == $element {cd $wd} {}} {}}; if (pwd) == $wd {cd $wd; echo \"No such path!\"} {}}",
|
||||
# ]
|
||||
#
|
||||
|
||||
export def --env c [dir] {
|
||||
let CD_PATH = [. ($env.NU_PLUGIN_DIRS | get 0) $nu.default-config-dir ]
|
||||
let wd = (pwd);
|
||||
for element in $CD_PATH {
|
||||
let element = ($element | path expand)
|
||||
if (pwd) == $wd {
|
||||
cd $element;
|
||||
for directory in (ls -a | where type == dir | get name) {
|
||||
if $dir == $directory {
|
||||
cd $dir
|
||||
break
|
||||
}
|
||||
};
|
||||
if (pwd) == $element {
|
||||
cd $wd
|
||||
}
|
||||
}
|
||||
};
|
||||
if (pwd) == $wd {
|
||||
cd $wd
|
||||
print "No such path!"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
### This clears out your screen buffer on a default mac terminal
|
||||
### currently there is no way to do that in nushell
|
||||
|
||||
def cls [] {
|
||||
ansi cls
|
||||
ansi clsb
|
||||
ansi home
|
||||
}
|
||||
21
dot_config/nushell/nu_scripts/sourced/cool-oneliners/dict.nu
Normal file
21
dot_config/nushell/nu_scripts/sourced/cool-oneliners/dict.nu
Normal file
@@ -0,0 +1,21 @@
|
||||
# Function querying free online English dictionary API for definition of given word(s)
|
||||
def dict [...word #word(s) to query the dictionary API but they have to make sense together like "martial law", not "cats dogs"
|
||||
] {
|
||||
let query = ($word | str join %20)
|
||||
let link = ('https://api.dictionaryapi.dev/api/v2/entries/en/' + ($query|str replace ' ' '%20'))
|
||||
let output = (http get $link | rename word)
|
||||
let w = ($output.word | first)
|
||||
|
||||
if $w == "No Definitions Found" {
|
||||
echo $output.word
|
||||
} else {
|
||||
echo $output
|
||||
| get meanings
|
||||
| flatten
|
||||
| select partOfSpeech definitions
|
||||
| flatten
|
||||
| flatten
|
||||
| reject "synonyms"
|
||||
| reject "antonyms"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# Combine two files into one
|
||||
|
||||
def create_files [] {
|
||||
[0,1,2,3] | range 0..3 | save a.json
|
||||
[4,5,6,7] | range 0..3 | save b.json
|
||||
}
|
||||
|
||||
create_files
|
||||
echo (open a.json) (open b.json) | save c.json
|
||||
open c.json | flatten
|
||||
rm a.json b.json c.json
|
||||
@@ -0,0 +1,7 @@
|
||||
# rename any SQL files in current directory from hello_file.sql to hello-file.sql
|
||||
ls ./*.sql | each { |f|
|
||||
let ext = (echo $f.name | path parse | get extension);
|
||||
let cur_stem = (echo $f.name | path parse | get stem);
|
||||
let new_name = (build-string (echo $cur_stem | str kebab-case) "." $ext)
|
||||
mv $f.name $new_name
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
## show directory sizes in current directory starting from the largest
|
||||
ls -d|where type == dir|sort-by size|reverse|format filesize GB size
|
||||
@@ -0,0 +1,12 @@
|
||||
# Search terms in the specified files and/or folders based on the glob pattern provided.
|
||||
def "find in" [
|
||||
glob: glob, # the glob expression
|
||||
...rest: any # terms to search
|
||||
]: nothing -> table<path: string, line: int, data: string> {
|
||||
glob $glob
|
||||
| par-each {|e|
|
||||
open $e | lines | enumerate | rename line data |
|
||||
find -c [data] ...$rest |
|
||||
each {|match| {path: ($e | path relative-to $env.PWD), ...$match}}
|
||||
} | flatten
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# gently try to delete merged branches, excluding the checked out one
|
||||
git branch --merged | lines | where $it !~ '\*' | str trim | where $it != 'master' and $it != 'main' | each { |it| git branch -d $it }
|
||||
@@ -0,0 +1,2 @@
|
||||
# Ingest JavaScript Map JSON into nu then to markdown
|
||||
open assets/js_map.json | each { echo [[Español English]; [ $in.0 $in.1]] } | flatten | to md
|
||||
@@ -0,0 +1,2 @@
|
||||
# Increment the minor version for any package.json in the current directory with `nu_plugin_inc` (eigenrick — 08/16/2020)
|
||||
ls -f */package.json | each {|it| open $it.name | inc version --minor | to json --indent 2 | save --raw --force $it.name }
|
||||
@@ -0,0 +1 @@
|
||||
open ~/.config/fish/fish_history | from yaml | get cmd | find --regex '^git .*' | split column ' ' command subcommand
|
||||
@@ -0,0 +1,4 @@
|
||||
# Print working directory but abbreviates the home dir as ~
|
||||
def pwd-short [] {
|
||||
$env.PWD | str replace $nu.home-path '~'
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# Makes an http request to a URL and gets the "value" field off the JSON response.
|
||||
(http get https://api.chucknorris.io/jokes/random).value
|
||||
@@ -0,0 +1,2 @@
|
||||
# Evaluates the top 5 most used commands present in `nushell/history.txt`.
|
||||
if $nu.history-enabled { open $nu.history-path | lines | uniq --count | sort-by --reverse count | first 5 | rename command amount } else { print --stderr "History is disabled!" }
|
||||
@@ -0,0 +1,6 @@
|
||||
# Search the WordprocessingML XML Schema definition file for a simple type by name
|
||||
# You'll need the wml.xsd file.
|
||||
# To get that file, first download the following zip:
|
||||
# https://www.ecma-international.org/wp-content/uploads/ECMA-376-Fifth-Edition-Part-1-Fundamentals-And-Markup-Language-Reference.zip
|
||||
# Then, unzip the contents of OfficeOpenXML-XMLSchema-Strict.zip.
|
||||
open wml.xsd | from xml | get content | where tag == simpleType | flatten | where name =~ BrType | get content.content.0.attributes
|
||||
Reference in New Issue
Block a user