nushell-config/config.nu

224 lines
6.1 KiB
Plaintext
Raw Normal View History

2024-02-19 05:52:08 +01:00
# Nushell Config File
#
# version = "0.90.1"
# Command existence checker function
def 'is-installed' [ app: string ] {
((which $app | length) > 0)
}
2024-03-17 19:36:23 +01:00
#
# 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
#
# ALIASES / CUSTOM COMMANDS
#
# weather
export alias weather = get_weather
2024-02-19 05:52:08 +01:00
# 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
2024-03-17 19:36:23 +01:00
# ls's
export alias la = ls -a
export alias ll = ls -l
export alias lal = ls -al
export alias lse = ^ls -lZ
2024-02-19 05:52:08 +01:00
# 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 }
# firewalld
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
# Execute bash on host (atomic desktop)
export alias hostexec = distrobox-host-exec bash
2024-03-17 19:36:23 +01:00
# APT
2024-02-19 05:52:08 +01:00
export alias acs = sudo apt-cache search
export alias acp = sudo apt-cache policy
export alias afs = sudo apt-file search
export alias afu = sudo apt-file update
export alias aac = sudo apt autoclean
export alias agc = sudo apt clean
export alias agi = sudo apt install
export alias agli = sudo apt list --installed
export alias agp = sudo apt purge
export alias agr = sudo apt remove
export alias agu = sudo apt update
export alias agud = sudo apt update and sudo apt dist-upgrade
export alias agar = sudo apt autoremove
2024-03-17 19:36:23 +01:00
# DNF
2024-02-19 05:52:08 +01:00
export alias dnfc = sudo dnf clean all
export alias dnfi = sudo dnf install
export alias dnfu = sudo dnf update
export alias dnfr = sudo dnf remove
export alias dnfs = sudo dnf search
# 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
2024-03-17 19:36:23 +01:00
def amimullvad [] { curl -sSL https://am.i.mullvad.net/json | from json }
2024-02-19 05:52:08 +01:00
# Uptime info
2024-03-17 19:36:23 +01:00
def upt [] { jc uptime | from json }
2024-02-19 05:52:08 +01:00
# df info
2024-03-17 19:36:23 +01:00
def dfj [] { jc df | from json }
2024-02-19 05:52:08 +01:00
# /etc/fstab info
def etc-fstab [] { open --raw /etc/fstab | jc --fstab | from json }
# memory free info
2024-03-17 19:36:23 +01:00
def memfree [] { jc free | from json }
2024-02-19 05:52:08 +01:00
# /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
2024-03-17 19:36:23 +01:00
def netcons [] { jc lsof -i | from json }
2024-02-19 05:52:08 +01:00
# Ports
2024-03-17 19:36:23 +01:00
def tulp [] { jc ss -tulp | from json }
2024-02-19 05:52:08 +01:00
# Open ports
2024-03-17 19:36:23 +01:00
def openports [] { sudo jc lsof -i | from json | find "LISTEN" }
2024-02-19 05:52:08 +01:00
# List sockets in use
2024-03-17 19:36:23 +01:00
def lsock [] { sudo jc lsof -nP | from json }
2024-02-19 05:52:08 +01:00
# List UDP sockets in use
2024-03-17 19:36:23 +01:00
def lsocku [] { sudo jc lsof -nP | from json | find "UDP" }
2024-02-19 05:52:08 +01:00
# List TCP sockets in use
2024-03-17 19:36:23 +01:00
def lsockt [] { sudo jc lsof -nP | from json | find "TCP" }
2024-02-19 05:52:08 +01:00
# 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 }
2024-03-17 19:36:23 +01:00
# extract
def x [filename: path] { extract $filename }
2024-02-19 05:52:08 +01:00
# 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
}
2024-03-17 19:36:23 +01:00
# Select a host to SSH into
2024-02-19 05:52:08 +01:00
def nussh [] {
let ssh_host = (ssh ssh-list | get Host | input list $"(ansi yellow)Which host to SSH into?(ansi reset)")
if ($ssh_host | describe) != "string" {
echo "Operation cancelled"
return
}
2024-03-17 19:36:23 +01:00
autossh -M 0 $ssh_host
2024-02-19 05:52:08 +01:00
}
2024-03-17 19:36:23 +01:00
# Select an open source license and save to LICENSE in current working directory
2024-02-19 05:52:08 +01:00
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
}
2024-03-17 19:36:23 +01:00
# Convert YAML to JSON
2024-02-19 05:52:08 +01:00
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)
}
2024-03-17 19:36:23 +01:00
# Download a file with httpie
def htdl [url: string] {
^http -d $url
}
2024-02-19 05:52:08 +01:00
$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 }
}
]
}