feat(fish): convert a few functions

This commit is contained in:
Stefan Imhoff
2023-06-27 11:39:51 +02:00
parent f0940ba15f
commit 46dc574bb9
8 changed files with 48 additions and 0 deletions

View File

@@ -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

View File

@@ -0,0 +1,3 @@
function encodeBase64 --description "Encodes images in Base64"
uuencode -m $argv[1] /dev/stdout | sed 1d | sed '$d'
end

3
fish/functions/fcd.fish Normal file
View File

@@ -0,0 +1,3 @@
function fcd --description "cd into directory"
cd (find * -type d | fzf --preview 'tree -C {} | head -50')
end

10
fish/functions/fe.fish Normal file
View File

@@ -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

4
fish/functions/fhcd.fish Normal file
View File

@@ -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

13
fish/functions/fs.fish Normal file
View File

@@ -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

View File

@@ -0,0 +1,3 @@
function server --description "Run a server with browser-sync"
browser-sync start --server --files "**"
end

View File

@@ -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