aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorDeposite Pirate2025-01-12 14:40:33 +0100
committerDeposite Pirate2025-01-12 14:40:33 +0100
commite7764f9b08072cfb67c2d3ecf075df9a80aee6fd (patch)
tree628d5f66e1d62f1d710bcbe472aa68b5e19522f8 /functions
parent62d7fa8cfa2e6de053d7c1238bd8fdcdf0cc8a7d (diff)
Import config.
Diffstat (limited to 'functions')
-rw-r--r--functions/chext.fish12
-rw-r--r--functions/fish_greeting.fish27
-rw-r--r--functions/fish_prompt.fish27
-rw-r--r--functions/mcd.fish4
-rw-r--r--functions/mkhomedirs.fish24
-rw-r--r--functions/rchmod.fish11
-rw-r--r--functions/renlow.fish21
-rw-r--r--functions/shcmds.fish57
-rw-r--r--functions/test-net.fish58
9 files changed, 241 insertions, 0 deletions
diff --git a/functions/chext.fish b/functions/chext.fish
new file mode 100644
index 0000000..5f8132f
--- /dev/null
+++ b/functions/chext.fish
@@ -0,0 +1,12 @@
+function chext --description 'Change extension of files with an extension' -a sourceext -a targetext
+
+if test (count $argv) -lt 2
+ echo 'Missing argument.'
+ return 1
+end
+
+for file in *.$sourceext
+ echo mv $file (path change-extension $targetext $file)
+end
+
+end
diff --git a/functions/fish_greeting.fish b/functions/fish_greeting.fish
new file mode 100644
index 0000000..2c8193d
--- /dev/null
+++ b/functions/fish_greeting.fish
@@ -0,0 +1,27 @@
+function fish_greeting
+
+ if not set -q TMUX
+
+ if set -q SSH_CONNECTION
+ if command -sq fastfetch
+ fastfetch -c paleofetch.jsonc
+ end
+
+ if command -sq bsdfetch
+ bsdfetch
+ end
+ end
+
+ if command -sq fortune
+ if string match -q -e 'Linux' (uname)
+ echo
+ fortune linux
+ echo
+ else
+ fortune
+ end
+ end
+
+ end
+
+end
diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish
new file mode 100644
index 0000000..2504066
--- /dev/null
+++ b/functions/fish_prompt.fish
@@ -0,0 +1,27 @@
+function fish_prompt --description 'Write out the prompt'
+ set -l last_pipestatus $pipestatus
+ set -l last_status $status
+ set -l normal (set_color normal)
+
+ # Color the prompt differently when we're root
+ set -l color_cwd $fish_color_cwd
+ set -l prefix
+ set -l suffix '>'
+ if contains -- $USER root toor
+ if set -q fish_color_cwd_root
+ set color_cwd $fish_color_cwd_root
+ end
+ set suffix '#'
+ end
+
+ # If we're running via SSH, change the host color.
+ set -l color_host $fish_color_host
+ if set -q SSH_TTY
+ set color_host $fish_color_host_remote
+ end
+
+ # Write pipestatus
+ set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
+
+ echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " "
+end
diff --git a/functions/mcd.fish b/functions/mcd.fish
new file mode 100644
index 0000000..2533622
--- /dev/null
+++ b/functions/mcd.fish
@@ -0,0 +1,4 @@
+function mcd --description 'Make and cd to a directory'
+ mkdir -p "$argv"
+ cd "$argv"
+end
diff --git a/functions/mkhomedirs.fish b/functions/mkhomedirs.fish
new file mode 100644
index 0000000..7052baf
--- /dev/null
+++ b/functions/mkhomedirs.fish
@@ -0,0 +1,24 @@
+function mkhomedirs --description 'Make common directories in $HOME'
+
+set -f saveumask (umask)
+umask 0077
+
+mkdir -p \
+ ~/Config \
+ ~/.config/fish/conf.d \
+ ~/.config/fish/functions \
+ ~/.local/bin \
+ ~/.local/share/nvim/site/pack/local/start \
+ ~/.gnupg
+
+if string match -q -e 'Linux' (uname)
+
+mkdir -p \
+ ~/.local/share/applications \
+ ~/.config/systemd/user
+
+end
+
+umask $saveumask
+
+end
diff --git a/functions/rchmod.fish b/functions/rchmod.fish
new file mode 100644
index 0000000..b54348f
--- /dev/null
+++ b/functions/rchmod.fish
@@ -0,0 +1,11 @@
+function rchmod --description 'Recursively reset premissions of files and folders'
+
+if not command -sq 'find'
+ echo "Can't find find."
+ return 1
+end
+
+find . -type d -exec chmod 755 {} +
+find . -type f -exec chmod 644 {} +
+
+end
diff --git a/functions/renlow.fish b/functions/renlow.fish
new file mode 100644
index 0000000..98b0e4c
--- /dev/null
+++ b/functions/renlow.fish
@@ -0,0 +1,21 @@
+function renlow --description 'Rename all files and directories with lowercase characters'
+
+if not command -sq 'find'
+ echo "Can't find find."
+ return 1
+end
+
+for file in (find . -type f)
+ set -l element (string split -r -m1 / $file)
+ mv $file $element[1]/(string lower $element[2])
+end
+
+set -f dirs (find . -type d)
+for dir in $dirs[-1..1] # Rename directories in reverse order
+ set -l element (string split -r -m1 / $dir)
+ if not test -z $element[2] # Catch .
+ mv $dir $element[1]/(string lower $element[2])
+ end
+end
+
+end
diff --git a/functions/shcmds.fish b/functions/shcmds.fish
new file mode 100644
index 0000000..c75b654
--- /dev/null
+++ b/functions/shcmds.fish
@@ -0,0 +1,57 @@
+function shcmds --description "View installed useful command line programs"
+
+if not functions -q is-installed
+ echo "No is-installed function defined."
+ return 1
+end
+
+set -f compress 'libarchive' 'bzip3' 'p7zip' 'unrar'
+set -f crypt 'age'
+set -f shell 'exa' 'tmux' 'walk' 'moar' 'most' 'fcp' 'b3sum'
+set -f editor 'neovim' 'micro' 'nano'
+set -f file 'mc' 'nnn'
+set -f bin 'hexyl'
+set -f text 'bat' 'ripgrep' 'sd' 'ugrep' 'grex' 'since' 'difftastic' 'vbindiff'
+set -f sys 'htop' 'btop' 'duf' 'ncdu' 'procs'
+set -f sec 'hashcat'
+set -f img 'viu' 'timg'
+set -f markdown 'glow' 'mdcat'
+set -f db 'csview' 'textql'
+set -f dev 'strace' 'lurk'
+set -f www 'links'
+set -f mail 'aerc'
+set -f gopher 'ncgopher'
+set -f gemini 'clagrange' 'amfora' 'ncgopher'
+set -f tox 'toxic'
+set -f ftp 'lftp'
+set -f http 'curlie' 'xh' 'hurl'
+set -f mirror 'wget' 'gemget' 'httrack' 'crawley'
+set -f dns 'doggo' 'dog'
+set -f netmon 'bandwhich' 'iftop' 'netscanner' 'trippy'
+set -f netsec 'nmap' 'ngrep' 'rustscan'
+set -f sync 'rsync'
+set -f man 'tldr'
+set -f sound 'sox' 'mp3gain'
+set -f graphics 'graphicsmagick'
+set -f xorg 'xdotool' 'yank'
+
+set -f -a mul $img $sound $graphics
+set -f -a net $www $mail $gopher $gemini $tox $ftp $http $mirror $dns $netmon $netsec
+set -f -a all $net $mul $compress $crypt $shell $editor $file $bin $text $sys $sec $markdown $db $dev $sync $man $xorg
+
+for element in (string join0 $all | sort -z | uniq -z | string split0)
+ if is-installed $element
+ set_color green
+ printf $element
+ set_color normal
+ else
+ set_color red
+ printf $element
+ set_color normal
+ end
+ printf ' '
+end
+
+printf '\n'
+
+end
diff --git a/functions/test-net.fish b/functions/test-net.fish
new file mode 100644
index 0000000..93b60aa
--- /dev/null
+++ b/functions/test-net.fish
@@ -0,0 +1,58 @@
+function test-net --description 'Test network connectivity'
+
+if not command -q 'ip'
+ echo "Can't find ip."
+ return 1
+end
+
+if not command -q 'ping'
+ echo "Can't find ping."
+ return 1
+end
+
+if not command -q 'curl'
+ echo "Can't find curl."
+ return 1
+end
+
+set -l extipurl 'https://ifconfig.io'
+
+function print_header -a headertext
+ echo
+ set_color blue
+ echo $headertext
+ set_color normal
+ echo
+end
+
+function print_ip -a label -a ip
+ echo -n $label
+ set_color yellow
+ echo $ip
+ set_color normal
+end
+
+function ping_host -a host
+ echo
+ set_color green
+ ping -q -O -c 1 $host
+ set_color normal
+end
+
+print_header "Testing local connectivity"
+
+set -l gateway "$(ip -c=never -o route show | awk '/default via/ {print $3}')"
+
+print_ip 'Gateway: ' "$gateway"
+ping_host "$gateway"
+
+print_header "Testing internet connectivity"
+
+print_ip 'External IPv4 address: ' "$(curl -s -4 $extipurl)"
+print_ip 'External IPv6 address: ' "$(curl -s -6 $extipurl)"
+
+ping_host 8.8.8.8
+
+echo
+
+end