mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
refactor: ✨ (#418)
* refactor: ✨ move in one commit Eveything in modules should probably be changed to `exported` defs. The idea is to move everything first to keep proper history. * refactor: 📝 add modules readme (wip) * refactor: ✨ small move * refactor: 📝 changed nestring, updated modules readme * refactor: 📝 to document or not to document * fix: 🐛 themes replaced the template to use `main` and regenerated them from lemnos themes. * Revert "fix: 🐛 themes" This reverts commit 4918d3633c8d2d81950a0ed0cfd9eb84241bc886. * refactor: ✨ introduce sourced - Created a source `root` in which sourcable demos are stored. Some might get converted to modules later on. - Moved some files to bin too. * fix: 🐛 fehbg.nu * fix: 🐛 modules/after.nu * moved some other stuff around --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
parent
382696cd21
commit
c47ccd42b8
128 changed files with 185 additions and 12 deletions
19
sourced/cool-oneliners/README.md
Normal file
19
sourced/cool-oneliners/README.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# cool oneliners
|
||||
|
||||
Capturing oneliners to and from the nushell Discourse channel `#cool-oneliners`.
|
||||
|
||||
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
|
12
sourced/cool-oneliners/cargo_search.nu
Normal file
12
sourced/cool-oneliners/cargo_search.nu
Normal file
|
@ -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
|
||||
}
|
8
sourced/cool-oneliners/clear_screen_buf.nu
Normal file
8
sourced/cool-oneliners/clear_screen_buf.nu
Normal file
|
@ -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
sourced/cool-oneliners/dict.nu
Normal file
21
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 = (fetch $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"
|
||||
}
|
||||
}
|
11
sourced/cool-oneliners/file_cat.nu
Normal file
11
sourced/cool-oneliners/file_cat.nu
Normal file
|
@ -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
|
7
sourced/cool-oneliners/file_convert_naming_case.nu
Normal file
7
sourced/cool-oneliners/file_convert_naming_case.nu
Normal file
|
@ -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
|
||||
}
|
2
sourced/cool-oneliners/git_gone.nu
Normal file
2
sourced/cool-oneliners/git_gone.nu
Normal file
|
@ -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 }
|
1
sourced/cool-oneliners/parse_fish_command_history.nu
Normal file
1
sourced/cool-oneliners/parse_fish_command_history.nu
Normal file
|
@ -0,0 +1 @@
|
|||
open ~/.config/fish/fish_history | from yaml | get cmd | find --regex '^git .*' | split column ' ' command subcommand
|
4
sourced/cool-oneliners/pwd-short.nu
Normal file
4
sourced/cool-oneliners/pwd-short.nu
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Print working directory but abbreviates the home dir as ~
|
||||
def pwd-short [] {
|
||||
$env.PWD | str replace $nu.home-path '~' -s
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue