1
0

Switch to fish shell

This commit is contained in:
2024-12-14 00:15:47 +01:00
parent d0db80b911
commit 2314780ed9
16 changed files with 275 additions and 296 deletions

View File

@@ -0,0 +1,20 @@
function clip
set -g stdin
if not tty -s >/dev/null
read stdin
end
set stdin $(string trim -- $stdin)
set -l argv $(string trim -- $argv)
if test -n "$argv"
echo "$argv" | xclip -selection clipboard
return 0
end
if test -n "$stdin"
echo "$stdin" | xclip -selection clipboard
return 0
end
xclip -selection clipboard -o
end

View File

@@ -0,0 +1,3 @@
function into
mkdir -p "$argv" && cd "$argv"
end

View File

@@ -0,0 +1,61 @@
function layout
argparse -n "layout" "v/verbose" "t/target=" -- $argv
or return 1
set _target
if set -q _flag_target
set _target "$_flag_target"
end
if test -f "$_TEMP/curr-layout"
if not set -q _flag_target
switch (cat "$_TEMP/curr-layout")
case us
set _target "sv"
case se
set _target "us"
case sv
set _target "us"
case '*'
if set -q _flag_verbose
echo "Unregognized layout set in /curr-layout file; stopping..."
end
return 1
end
end
else
if set -q _flag_verbose; and not set -q _flag_target
echo "Could not determine current layout; defaulting to US"
end
echo "us" > "$_TEMP/curr-layout"
if not set -q _flag_target
set _target "sv"
end
end
if not set -q _target
return 2
end
if set -q _flag_verbose
switch (echo $_target)
case sv
echo "Switching to Swedish layout..."
case us
echo "Switching to U.S. layout..."
end
end
switch (echo $_target)
case sv
set _target se
case '*'
end
if setxkbmap -layout $_target
echo $_target > "$_TEMP/curr-layout"
end
return $status
end

View File

@@ -0,0 +1,22 @@
function round
argparse -n "round" -i "p/precision=!_validate_int" -- $argv
or return 1
set -l value $argv
set -l precision 0
if set -q _flag_precision
set precision $_flag_precision
end
set precision $(math 10 ^ $precision)
set value $(math $value x $precision)
set -l right $(math $value % 1)
set value $(math $value - $right)
set value $(math $value / $precision)
echo $value
end

View File

@@ -0,0 +1,84 @@
function vpn
argparse -n "vpn" -x e,d -x q,s 'e/enable' 'd/disable' 's/status' 'q/quiet' 'f/force' -- $argv
or return 1
set _silent false
if set -q _flag_quiet
set _silent true
end
set _path ~/wg0.conf
set _status false
if test -f "$_TEMP/vpn-status"
switch (cat "$_TEMP/vpn-status")
case true
set _status true
case false
set _status false
case '*'
if not $_quiet
echo "Unregognized /vpn-status contents, exiting!"
end
return 1
end
else
if not $_silent
echo "Did not find status file; creating..."
echo "false" >> "$_TEMP/vpn-status"
end
end
if set -q _flag_status
if $_status
echo "VPN is active."
else
echo "VPN is inactive."
end
return 0
end
if not set -q _flag_enable; and not set -q _flag_disable
if $_status
set _flag_disable
else
set _flag_enable
end
end
if set -q _flag_enable
if $_status; and not set -q _flag_force
if not $_silent
echo "Already enabled."
end
return 0
end
if wg-quick up $_path
echo "true" > "$_TEMP/vpn-status"
if not $_silent
echo "Successfully enabled."
end
end
return $status
end
if set -q _flag_disable
if not $_status; and not set -q _flag_force
if not $_silent
echo "Already disabled."
end
return 0
end
if wg-quick down $_path
echo "false" > "$_TEMP/vpn-status"
if not $_silent
echo "Successfully disabled."
end
end
return $status
end
return 2
end