mirror of
https://github.com/Steffo99/config-fish.git
synced 2024-12-22 06:44:22 +00:00
Add gen-repo-media
This commit is contained in:
parent
7f85c461b9
commit
e7a9b9bbcb
2 changed files with 89 additions and 0 deletions
27
completions/gen-repo-media.fish
Normal file
27
completions/gen-repo-media.fish
Normal file
|
@ -0,0 +1,27 @@
|
|||
function __gen-repo-media_is_at_arg
|
||||
set args (commandline --current-process --cut-at-cursor --tokenize)
|
||||
set len (count $args)
|
||||
if [ "$len" -ne "$argv[1]" ]
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
function __gen-repo-media_complete_icons
|
||||
set org (commandline --current-process --cut-at-cursor --tokenize)[2]
|
||||
set files (find "$HOME/Pictures/Avatars/$org/emblems-512x512/solid" -mindepth '1' -maxdepth '1' -type 'f' -iname '*.svg' -printf '%P\n')
|
||||
for file in $files
|
||||
string replace --regex '[.]svg$' "" "$file"
|
||||
end
|
||||
end
|
||||
|
||||
complete \
|
||||
--command='gen-repo-media' \
|
||||
--no-files \
|
||||
--condition='__gen-repo-media_is_at_arg 1' \
|
||||
--arguments='(find "$HOME/Pictures/Avatars" -mindepth 1 -maxdepth 1 -type d -printf "%P\n")'
|
||||
|
||||
complete \
|
||||
--command='gen-repo-media' \
|
||||
--no-files \
|
||||
--condition='__gen-repo-media_is_at_arg 2' \
|
||||
--arguments='(__gen-repo-media_complete_icons)'
|
62
functions/gen-repo-media.fish
Normal file
62
functions/gen-repo-media.fish
Normal file
|
@ -0,0 +1,62 @@
|
|||
function gen-repo-media
|
||||
log-i "Generating" ".media" "directory for this repository..."
|
||||
|
||||
set org $argv[1]
|
||||
|
||||
if [ -z "$org" ]
|
||||
log-f "Missing" "org" "parameter (#1)."
|
||||
exit 1
|
||||
else
|
||||
log-d "Using organization:" "$org"
|
||||
end
|
||||
|
||||
set icon $argv[2]
|
||||
|
||||
if [ -z "$icon" ]
|
||||
log-f "Missing" "icon" "parameter (#2)."
|
||||
exit 1
|
||||
else
|
||||
log-d "Using icon:" "$org"
|
||||
end
|
||||
|
||||
set emblem_svg "$HOME/Pictures/Avatars/$org/emblems-512x512/solid/$icon.svg"
|
||||
|
||||
if [ ! -f "$emblem_svg" ]
|
||||
log-f "Emblem SVG at" "$emblem_svg" "does not exist."
|
||||
exit 2
|
||||
else
|
||||
log-d "Using emblem SVG:" "$emblem_svg"
|
||||
end
|
||||
|
||||
set emblem_512x512 "$HOME/Pictures/Avatars/$org/emblems-512x512/solid/$icon.png"
|
||||
|
||||
if [ ! -f "$emblem_512x512" ]
|
||||
log-f "Emblem 512x512 at" "$emblem_512x512" "does not exist."
|
||||
exit 2
|
||||
else
|
||||
log-d "Using emblem 512x512:" "$emblem_512x512"
|
||||
end
|
||||
|
||||
set emblem_128x128_round "$HOME/Pictures/Avatars/$org/emblems-128x128_round/solid/$icon.png"
|
||||
|
||||
if [ ! -f "$emblem_128x128_round" ]
|
||||
log-f "Round emblem 128x128 at" "$emblem_128x128_round" "does not exist."
|
||||
exit 2
|
||||
else
|
||||
log-d "Using round emblem 128x128:" "$emblem_128x128_round"
|
||||
end
|
||||
|
||||
log-t "Creating" ".media" "directory..."
|
||||
command mkdir .media
|
||||
|
||||
log-t "Copying" "emblem SVG" "..."
|
||||
command cp "$emblem_svg" ".media/icon.svg"
|
||||
|
||||
log-t "Copying" "emblem 512x512" "..."
|
||||
command cp "$emblem_512x512" ".media/icon-512x512.png"
|
||||
|
||||
log-t "Copying" "round emblem 128x128" "..."
|
||||
command cp "$emblem_128x128_round" ".media/icon-128x128_round.svg"
|
||||
|
||||
log-s "Successfully set up" "repository media" "!"
|
||||
end
|
Loading…
Reference in a new issue