mirror of
https://codeberg.org/hyperreal/nushell-config
synced 2024-11-01 08:43:12 +01:00
257 lines
6.2 KiB
Plaintext
257 lines
6.2 KiB
Plaintext
# Nushell Config File
|
|
|
|
# Command existence checker function
|
|
def 'is-installed' [ app: string ] {
|
|
((which $app | length) > 0)
|
|
}
|
|
|
|
# Global vars and consts
|
|
let hostn = (sys | get host.hostname)
|
|
const MODDIR = ($nu.default-config-dir | path join "modules")
|
|
|
|
|
|
#
|
|
# MODULES
|
|
#
|
|
|
|
# weather
|
|
use ~/.config/nushell/modules/get-weather.nu get_weather
|
|
|
|
# ultimate-extractor
|
|
use ~/.config/nushell/modules/ultimate-extractor.nu extract
|
|
|
|
# ssh
|
|
use ~/.config/nushell/modules/ssh.nu
|
|
|
|
# Source distro-specific modules
|
|
const DEBIAN_CONF = ($MODDIR | path join "debian.nu")
|
|
const REDHAT_CONF = ($MODDIR | path join "redhat.nu")
|
|
const DISTRO_CONFIG = if ("/etc/debian_version" | path exists) {
|
|
$DEBIAN_CONF
|
|
} else if ("/etc/redhat-release" | path exists) {
|
|
$REDHAT_CONF
|
|
} else {
|
|
$nu.env-path
|
|
}
|
|
source $DISTRO_CONFIG
|
|
|
|
#
|
|
# ALIASES / CUSTOM COMMANDS
|
|
#
|
|
|
|
# Copy nushell config to git repo
|
|
def cpnurepo [] {
|
|
let repo = ($nu.home-path | path join "repos/codeberg.org/hyperreal/nushell-config")
|
|
cp -v $nu.config-path $repo
|
|
cp -v $nu.env-path $repo
|
|
cp -rfv $MODDIR $repo
|
|
echo "Nushell config copied to local repo"
|
|
}
|
|
|
|
# Custom commands for Doom Emacs
|
|
def doomdoc [] { ~/.config/emacs/bin/doom doctor }
|
|
def dsync [] { ~/.config/emacs/bin/doom sync }
|
|
def dclean [] { ~/.config/emacs/bin/doom clean }
|
|
def dcomp [] { ~/.config/emacs/bin/doom compile }
|
|
def dpurge [] { ~/.config/emacs/bin/doom purge }
|
|
def denv [] { ~/.config/emacs/bin/doom env }
|
|
def dupgrade [] { ~/.config/emacs/bin/doom upgrade }
|
|
|
|
# weather
|
|
export alias weath = get_weather
|
|
|
|
# firewalld aliases
|
|
export alias fw = sudo firewall-cmd
|
|
export alias fwp = sudo firewall-cmd --permanent
|
|
export alias fwr = sudo firewall-cmd --reload
|
|
export alias fwrp = sudo firewall-cmd --runtime-to-permanent
|
|
|
|
# Git aliases
|
|
export alias ga = git add
|
|
export alias gcl = git clone
|
|
export alias gcmsg = git commit -m
|
|
export alias gd = git diff
|
|
export alias gl = git pull
|
|
export alias gp = git push
|
|
export alias gr = git remote
|
|
export alias grbi = git rebase -i
|
|
export alias grm = git rm
|
|
export alias grv = git remote -v
|
|
export alias gst = git status
|
|
|
|
# ls's
|
|
export alias la = ls -a
|
|
export alias ll = ls -l
|
|
export alias lal = ls -al
|
|
export alias lse = ^ls -lZ
|
|
|
|
# Copy trimmed GPG fingerprint to clipboard
|
|
def gpgfpr [] {
|
|
gpg -K --with-colons
|
|
| jc --gpg
|
|
| from json
|
|
| get 1.user_id
|
|
| xclip -sel clipboard
|
|
}
|
|
|
|
# Copy SSH public key to clipboard
|
|
def pubkey [] {
|
|
open --raw ~/.ssh/id_ed25519.pub
|
|
| str trim
|
|
| xclip -selection clipboard
|
|
}
|
|
|
|
# Get public ip info
|
|
def pubip [] { curl --silent ipinfo.io | from json }
|
|
|
|
# Get Mullvad info
|
|
def amimullvad [] {
|
|
curl -sSL https://am.i.mullvad.net/json
|
|
| from json
|
|
}
|
|
|
|
# Uptime info
|
|
def upt [] { jc uptime | from json }
|
|
|
|
# df info
|
|
def dfj [] { jc df | from json }
|
|
|
|
# /etc/fstab info
|
|
def etc-fstab [] {
|
|
open --raw /etc/fstab
|
|
| jc --fstab
|
|
| from json
|
|
}
|
|
|
|
# memory free info
|
|
def memfree [] { jc free | from json }
|
|
|
|
# /etc/group
|
|
def etc-group [] {
|
|
open --raw /etc/group
|
|
| jc --group
|
|
| from json
|
|
}
|
|
|
|
# /etc/passwd
|
|
def etc-passwd [] {
|
|
open --raw /etc/passwd
|
|
| jc --passwd
|
|
| from json
|
|
}
|
|
|
|
# Network connections
|
|
def netcons [] { jc lsof -i | from json }
|
|
|
|
# Ports
|
|
def tulp [] { jc ss -tulp | from json }
|
|
|
|
# Open ports
|
|
def openports [] {
|
|
sudo jc lsof -i
|
|
| from json
|
|
| find "LISTEN"
|
|
}
|
|
|
|
# List sockets in use
|
|
def lsock [] { sudo jc lsof -nP | from json }
|
|
|
|
# List UDP sockets in use
|
|
def lsocku [] { sudo jc lsof -nP | from json | find "UDP" }
|
|
|
|
# List TCP sockets in use
|
|
def lsockt [] { sudo jc lsof -nP | from json | find "TCP" }
|
|
|
|
# Print timestamp as %FT%T%:z
|
|
def tstampz [] { date now | format date "%FT%T%:z" }
|
|
|
|
# Create new directory and enter it
|
|
def --env mkd [path] { mkdir $path; cd $path }
|
|
|
|
# Display pid info of command
|
|
def pids [cmd] { ps | where name == $cmd }
|
|
|
|
# Get time in specific time zone
|
|
def whattimein [string] {
|
|
date now
|
|
| date to-timezone $string
|
|
}
|
|
|
|
# cd to home and clear screen
|
|
def --env rsrc [] { cd $env.HOME; clear }
|
|
|
|
# extract
|
|
def x [filename: path] { extract $filename }
|
|
|
|
# Convert filename to given case
|
|
# Ex. caseify camel hello_world.txt
|
|
# => helloWorld.txt
|
|
# Based on https://github.com/nushell/nu_scripts/blob/main/sourced/cool-oneliners/file_convert_naming_case.nu
|
|
def caseify [case: string, filename: path] {
|
|
let ext = (echo $filename | path parse | get extension)
|
|
let cur_stem = (echo $filename | path parse | get stem)
|
|
let new_name = match $case {
|
|
"camel" => (((echo $cur_stem | str camel-case) + "." + $ext) | str join),
|
|
"kebab" => (((echo $cur_stem | str kebab-case) + "." + $ext) | str join),
|
|
"lower" => (((echo $cur_stem | str downcase) + "." + $ext) | str join),
|
|
"pascal" => (((echo $cur_stem | str pascal-case) + "." + $ext) | str join),
|
|
"screamsnake" => (((echo $cur_stem | str screaming-snake-case) + "." + $ext) | str join),
|
|
"snake" => (((echo $cur_stem | str snake-case) + "." + $ext) | str join),
|
|
_ => "Invalid case option"
|
|
}
|
|
mv $filename $new_name
|
|
}
|
|
|
|
# Select a host to SSH into
|
|
def nussh [] {
|
|
let ssh_host = (ssh ssh-list | get Host | input list $"\n(ansi red)Which host to SSH into?(ansi reset)")
|
|
if ($ssh_host | describe) != "string" {
|
|
echo "Operation cancelled"
|
|
return
|
|
}
|
|
autossh -M 0 $ssh_host
|
|
}
|
|
|
|
# Select an open source license and save to LICENSE in current working directory
|
|
def nulicense [] {
|
|
let licenses = (http get https://api.github.com/licenses)
|
|
let license_name = ($licenses | get name | input list $"(ansi yellow)Choose an open source license:(ansi reset)")
|
|
if ($license_name | describe) != "string" {
|
|
echo "Operation cancelled"
|
|
return
|
|
}
|
|
let license_body = (http get ($licenses | where name == $license_name).url.0).body
|
|
$license_body | save --raw -f LICENSE
|
|
}
|
|
|
|
# Convert YAML to JSON
|
|
def yaml2json [filename: path] {
|
|
let stem = (echo $filename | path parse | get stem)
|
|
open --raw $filename | from yaml | to json | save --raw ($stem + ".json" | str join)
|
|
}
|
|
|
|
# Download a file with httpie
|
|
def httpie [url: string] {
|
|
^http -d $url
|
|
}
|
|
|
|
$env.config = {
|
|
rm: {
|
|
always_trash: true
|
|
}
|
|
|
|
table: {
|
|
show_empty: false
|
|
}
|
|
|
|
keybindings: [
|
|
{
|
|
name: nussh
|
|
modifier: alt
|
|
keycode: char_s
|
|
mode: [emacs vi_normal vi_insert]
|
|
event: { send: executehostcommand cmd: nussh }
|
|
}
|
|
]
|
|
}
|