From 46dc574bb99f8d59a212f389311148e70dd2bc53 Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Tue, 27 Jun 2023 11:39:51 +0200 Subject: [PATCH] feat(fish): convert a few functions --- fish/functions/dataUrl.fish | 7 +++++++ fish/functions/encodeBase64.fish | 3 +++ fish/functions/fcd.fish | 3 +++ fish/functions/fe.fish | 10 ++++++++++ fish/functions/fhcd.fish | 4 ++++ fish/functions/fs.fish | 13 +++++++++++++ fish/functions/server.fish | 3 +++ fish/functions/unquarantine.fish | 5 +++++ 8 files changed, 48 insertions(+) create mode 100644 fish/functions/dataUrl.fish create mode 100644 fish/functions/encodeBase64.fish create mode 100644 fish/functions/fcd.fish create mode 100644 fish/functions/fe.fish create mode 100644 fish/functions/fhcd.fish create mode 100644 fish/functions/fs.fish create mode 100644 fish/functions/server.fish create mode 100644 fish/functions/unquarantine.fish diff --git a/fish/functions/dataUrl.fish b/fish/functions/dataUrl.fish new file mode 100644 index 0000000..471e5df --- /dev/null +++ b/fish/functions/dataUrl.fish @@ -0,0 +1,7 @@ +function dataUrl --description "Create a data URL from a file" + set mimeType (file -b --mime-type $argv) + if string match -r '^text/' $mimeType + set mimeType "$mimeType;charset=utf-8" + end + echo "data:$mimeType;base64,(openssl base64 -in $argv | tr -d '\n')" +end diff --git a/fish/functions/encodeBase64.fish b/fish/functions/encodeBase64.fish new file mode 100644 index 0000000..c954a3e --- /dev/null +++ b/fish/functions/encodeBase64.fish @@ -0,0 +1,3 @@ +function encodeBase64 --description "Encodes images in Base64" + uuencode -m $argv[1] /dev/stdout | sed 1d | sed '$d' +end diff --git a/fish/functions/fcd.fish b/fish/functions/fcd.fish new file mode 100644 index 0000000..e255fe3 --- /dev/null +++ b/fish/functions/fcd.fish @@ -0,0 +1,3 @@ +function fcd --description "cd into directory" + cd (find * -type d | fzf --preview 'tree -C {} | head -50') +end diff --git a/fish/functions/fe.fish b/fish/functions/fe.fish new file mode 100644 index 0000000..13aa957 --- /dev/null +++ b/fish/functions/fe.fish @@ -0,0 +1,10 @@ +# fe [FUZZY PATTERN] - Open the selected file with the default editor +# - Bypass fuzzy finder if there's only one match (--select-1) +# - Exit if there's no match (--exit-0) +function fe --description "Open the selected file with the default editor" + set files (fzf-tmux --query=$argv --multi --select-1 --exit-0 | string split \n) + + if test -n "$files" + $EDITOR $files; and true # This line is added to prevent failure when using "set -e" in shell. + end +end diff --git a/fish/functions/fhcd.fish b/fish/functions/fhcd.fish new file mode 100644 index 0000000..1faca77 --- /dev/null +++ b/fish/functions/fhcd.fish @@ -0,0 +1,4 @@ +function fhcd --description "Jump to home directory and search for directories" + cd $HOME + cd (find * -type d | fzf --preview 'tree -C {} | head -50') +end diff --git a/fish/functions/fs.fish b/fish/functions/fs.fish new file mode 100644 index 0000000..39d8546 --- /dev/null +++ b/fish/functions/fs.fish @@ -0,0 +1,13 @@ +function fs --description "Determine size of a file or total size of a directory" + if du -b /dev/null >/dev/null 2>&1 + set arg -sbh + else + set arg -sh + end + + if test -n "$argv" + du $arg -- $argv + else + du $arg .[^.]* * + end +end diff --git a/fish/functions/server.fish b/fish/functions/server.fish new file mode 100644 index 0000000..be321cc --- /dev/null +++ b/fish/functions/server.fish @@ -0,0 +1,3 @@ +function server --description "Run a server with browser-sync" + browser-sync start --server --files "**" +end diff --git a/fish/functions/unquarantine.fish b/fish/functions/unquarantine.fish new file mode 100644 index 0000000..22ecc2c --- /dev/null +++ b/fish/functions/unquarantine.fish @@ -0,0 +1,5 @@ +function unquarantine --description "Manually remove a downloaded app or file from the quarantine" + for attribute in com.apple.metadata:kMDItemDownloadedDate com.apple.metadata:kMDItemWhereFroms com.apple.quarantine + xattr -r -d "$attribute" $argv + end +end