Last active
August 8, 2020 10:35
-
-
Save chapmanjacobd/8d07e724e6077016532ff5f95185b238 to your computer and use it in GitHub Desktop.
fish functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sponge | |
/usr/bin/mkdir -p (dirname "$argv") | |
/usr/bin/sponge "$argv" | |
end | |
function tee | |
/usr/bin/mkdir -p (dirname "$argv") | |
/usr/bin/tee "$argv" | |
end | |
function repeat | |
while $argv | |
and : | |
end | |
end | |
function watchLog | |
while true | |
set x (log -o short-monotonic | tr '-' ' '| sed '1d' | cut -d' ' -f5- | awk 'BEGIN{RS="\n";ORS="\n\n"}1' | sed 's/entries//g') | |
if test -n "$x" | |
notify-send "Log" "$x" | |
sleep (math "5*60") | |
end | |
end | |
end | |
function log | |
journalctl --since "5 minutes ago" $argv | grep -v -E 'postfix|Firewall|pam|syncthing' | less -FSRXc | |
end | |
function trash | |
kioclient move (echo $argv | swallowFlags) trash:/ | |
end | |
function untrash | |
#mv -iv ~/.local/share/Trash/files/$argv[1] ./ | |
mv -iv ~/.local/share/Trash/files/(ls -snew -G /home/xk/.local/share/Trash/files/ | tail -1) "./$argv" | |
end | |
# view all folders with a depth of 2 | |
function l | |
setterm -linewrap off | |
tree -Lh 2 --sort=mtime --dirsfirst -d -h --prune --du -up -C $argv | |
setterm -linewrap on | |
end | |
# view all files with a depth of 3 | |
function f | |
setterm -linewrap off | |
tree -FLh 3 --sort=mtime --dirsfirst --prune --du --noreport -up -C $argv | grep -v '/$' | |
setterm -linewrap on | |
end | |
# insert string between filename and extension | |
function fileSuffix | |
set filen (string split -r -m1 . "$argv[1]")[1] | |
set filext (string split -r -m1 . "$argv[1]")[2] | |
echo $filen.$argv[2].$filext | |
end | |
abbr bc bc -ql | |
abbr sys systemctl | |
abbr qt qutebrowser | |
function screenbigdpi | |
xrandr --dpi 192 | |
echo 'Xft.dpi: 192' | xrdb -override | |
sed -i 's/ScaleFactor=1/ScaleFactor=2' ~/.config/kdeglobals | |
set fopt layout.css.devPixelsPerPx | |
set fset 2 | |
cd ~/.mozilla/firefox/*.default/ | |
sed -i 's/user_pref("'$fopt'",.*);/user_pref("'$fopt'","'$fset'");/' user.js | |
grep -q $fopt user.js || echo "user_pref(\"$fopt\",$fset);" >>user.js | |
end | |
function screensmalldpi | |
xrandr --dpi 96 | |
echo 'Xft.dpi: 96' | xrdb -override | |
sed -i 's/ScaleFactor=2/ScaleFactor=1' ~/.config/kdeglobals | |
set fopt layout.css.devPixelsPerPx | |
set fset 1 | |
cd ~/.mozilla/firefox/*.default/ | |
sed -i 's/user_pref("'$fopt'",.*);/user_pref("'$fopt'","'$fset'");/' user.js | |
grep -q $fopt user.js || echo "user_pref(\"$fopt\",$fset);" >>user.js | |
end | |
# can use like this: mpvonce (files | fileTypeVideos | head -1) | |
function files | |
find . -maxdepth 1 -not -type d -exec du -h {} + | sort -h $argv | cut -f2 | |
end | |
function fish_greeting | |
cat /proc/loadavg | cut -d' ' -f 2 | |
shuf -n 4 ~/mdrive/notes/(ls -p ~/mdrive/notes/ |grep -v / | shuf -n 1) | cowsay -W 52 -f tux | |
end | |
function fcd | |
cd (find -type d | fzf) | |
end | |
function zo --description 'open target dir' | |
__z -d $argv | |
end | |
function savefilenames | |
setterm -linewrap off | |
tree -Lh 2 --sort=mtime --dirsfirst -h --prune --du -up -C $argv | |
setterm -linewrap on | |
end | |
function la | |
ls -lahZt $argv | |
end | |
function o | |
xdg-open $argv & disown | |
disown (jobs -p) | |
exit | |
end | |
function temp | |
cat /sys/class/thermal/thermal_zone*/temp | |
end | |
function getfile | |
scp -F ~/.ssh/config_user_unli '[email protected]:/home/user/$argv[1]' ./ | |
end | |
function senddev | |
rsync -z -P -e "ssh -F /home/xk/.ssh/config_dev" $argv [email protected]:/home/user/ | |
end | |
function connectpg | |
ssh -i /home/xk/.ssh/key -L 5432:localhost:5432 [email protected] | |
end | |
function unli | |
ssh $argv [email protected] -i /home/xk/.ssh/key -t 'tmux a -t base || tmux new -s base' | |
end | |
function unliadmin | |
sshfs -o reconnect,IdentityFile=/home/xk/.ssh/key [email protected]:/ ~/unli | |
end | |
function sendroid | |
adb push $argv[1] /storage/self/primary/ | |
end | |
function sendroidsd | |
adb push $argv[1] /storage/16EA-0644/ | |
end | |
function sendroidmusic | |
adb push (find ~/Music/MusicLibrary/ -type f | shuf -n2000) /storage/self/primary/Music | |
end | |
function mp | |
mpv --input-ipc-server=/tmp/mpvsocket --shuffle --no-video /home/xk/Music/ | |
end | |
function ytdl.ogg | |
cd ~/Music/New | |
youtube-dl --extract-audio --audio-format opus $argv | |
end | |
function resizecityphotos | |
cd /home/xk/dataprojects/travelplanner/cityphotos/original/ | |
mogrify -path /home/xk/dataprojects/travelplanner/cityphotos/web/view/ -strip -interlace Plane -sampling-factor 4:2:0 -quality 85% -colorspace RGB -format jpg -resize "900x270^" -gravity center -crop 900x270+0+0 +repage *.jpg | |
mogrify -path /home/xk/dataprojects/travelplanner/cityphotos/web/detail/ -strip -interlace Plane -sampling-factor 4:2:0 -quality 85% -colorspace RGB -format jpg -resize "2048x1080^" -gravity center -crop 2048x1080+0+0 +repage *.jpg | |
end | |
function scr | |
scrot output.png | |
convert output.png \( -clone 0 -crop 48x48+700+560 -repage 240x48+0+0 \) \( -clone 0 -crop 48x48+850+420 -repage 240x48+48+0 \) \( -clone 0 -crop 48x48+950+550 -repage 240x48+96+0 \) \( -clone 0 -crop 48x48+1200+400 -repage 240x48+144+0 \) \( -clone 0 -crop 48x48+1200+800 -repage 240x48+192+0 \) -flatten -crop 240x48+0+0 output.png | |
end | |
function splitcsv | |
awk -v l=2000000 '(NR==1){header=$0;next} | |
(NR%l==2) { | |
c=sprintf("%0.5d",c+1); | |
close(file); file=FILENAME; sub(/csv$/,c".csv",file) | |
print header > file | |
} | |
{print $0 > file}' $argv | |
end | |
function getwebtext | |
wget -qO- $argv | html2text > (eval $argv.txt) | |
end | |
function sp | |
google-chrome https://www.pexels.com/search/$argv | |
google-chrome https://unsplash.com/search/photos/$argv | |
google-chrome https://pixabay.com/en/photos/$argv | |
google-chrome 'https://www.flickr.com/search/?text='$argv'&license=7%2C9%2C10&sort=date-taken-desc' | |
google-chrome https://stocksnap.io/search/$argv | |
end | |
function wclone | |
cd ~/backups/web/ | |
wget -e robots=off -np -nc -r -l inf -p $argv | |
end | |
function ffclip | |
ffmpeg -i "$argv[1]" -ss "$argv[2]". -c copy -to "$argv[3]". (fileSuffix "$argv[1]" "$argv[4]") | |
end | |
function ffmpegMakeSmall | |
ffmpeg -i "$argv[1]" -vf "scale=w=min(iw\,960):h=-2" -vcodec libx265 -preset 1 (fileSuffix "$argv[1]" small) | |
end | |
# force myself to learn new things: | |
abbr cd echo "use z" | |
abbr cat bat | |
abbr grep rg | |
function ls | |
status --is-interactive | |
and exa --git --long --header --classify --group-directories-first $argv | |
or /usr/bin/ls $argv | |
end | |
abbr ping prettyping | |
abbr man tldreakish/812425 | |
abbr search ag | |
abbr mkdir mkdir -pv | |
abbr less less -FSRXc | |
abbr find fd | |
abbr ps procs | |
abbr rm trash | |
abbr loop loop-rs | |
abbr qt qutebrowser | |
abbr sdi sudo dnf install | |
abbr sdu sudo dnf update | |
abbr sys systemctl | |
abbr xclip xclip -selection c | |
abbr top htop | |
abbr du ncdu | |
function mpvonce | |
mpv "$argv[1]" | |
kioclient move "$argv[1]" trash:/ | |
end | |
function fileTypeVideos | |
grep -E 'avi|mp4|m4a|m4v|mov|mkv' | |
end | |
function fileTypeAudio | |
grep -E 'flac|mp3|m4a|wav|[.]og[g|a]' | |
end | |
function git_changelog --description 'Prints git log in a way convenient for writing release notes' --argument range | |
test -n "$range" | |
or set range (git describe --abbrev=0)".." | |
git --no-pager log --reverse --format="* %s" $range | |
end | |
function copy-last-command | |
history | head -1 | xclip -selection c | |
end | |
abbr clipboard 'xclip -o -sel clip' | |
# rename files in folder to lowercase | |
for dir in (files) | |
mv $dir (echo $dir | tr '[:upper:]' '[:lower:]') | |
end | |
function tm_split_path -d 'Return filename, ext, and directory from the path' | |
echo $argv[1] | sed 's/\(.*\)\/\(.*\)\.\(.*\)$/\2\n\3\n\1/' | |
end | |
https://github.com/brigand/fish-functions/blob/master/functions/td.fish | |
https://github.com/brigand/fish-functions/blob/master/functions/chrome-profile.fish | |
https://github.com/brigand/fish-functions/blob/master/functions/gist.fish | |
https://github.com/lukaszlenart/fish-functions/blob/master/docker-cleanup.fish |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment