Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: feature – support miligrams – appimage compressed plugins #554

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions lib/annex/mg/functions/mg::before-load-handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env zsh
# -*- mode: sh;sh-indentation: 4;indent-tabs-mode: nil;sh-basic-offset: 4; -*-
# Copyright (c) 2020 Sebastian Gniazdowski

mg::before-load-handler() {
# Set the base and typically useful options.
builtin emulate -L zsh -o extendedglob -o warncreateglobal \
-o typesetsilent -o noshortloops \
-o rcquotes

local type=$1 SID=$2 id_as=$3 args=$4 ices=$5 hook=$6 subtype=$7

# Conditionally enable the output fr+om this annex
integer IBSHOW_MESSAGES=$+ICE[debug]+$+ZINIT[DEBUG]

# Exclude IDs with slashes and also packages
[[ $SID != *.mg && $+ICE[mg] != 1 ]] && return 0
[[ $SID == */* ]] && local BAD_ID=1 Q=1
[[ $SID == *:* ]] && local BAD_ID2=1 Q=1
(( $+ICE[pack] )) && local IS_PACK=1 Q=1
if ((Q));then
mg::msg "$BAD_ID" "$BAD_ID2" "$BAD_TELE" "$IS_PACK"
return 1
fi

local -a match mbegin mend reply
local MATCH REPLY
integer MBEGIN MEND QRET

local -A tpe_map
tpe_map=( 0 plugin 1 snippet )

# Strip the ID from some possible accidental /-s.
SID=${${SID#@}%%(.mg|/##)##}

# I've pressed C-J. Will now press C-J and C-H a few times
# So the completion-method switching doesn't seem to work.
mg::mount "$SID"
QRET=$?
if ((QRET));then
if (( QRET == 8 ));then
if [[ -z $ICE[mg] ]];then
+zinit-message {e}no such miligram: \
{file}$SID.mg{error}, and no \
{pid}user/plugin {error}provided in \
{ice}mc\'\'{error} ice, cannot \(down\)load \
the miligram file{…}
return QRET
elif [[ $ICE[mg] != ([^/]##)/([^/]##) ]];then
+zinit-message {e}no such miligram: \
{file}$SID.mg{error}, and incorrect {ice}mg\'\' \
{error}given, it should be in \
{pid}user/plugin {error}format, cannot \
\(down\)load the miligram file{…}
return QRET
fi
else
return QRET
fi
mg::ghr::download-mg "$ICE[mg]" "$SID" ""||return $?
mg::mount "$SID"||return $?
fi

##
## Save in $Plugins hash
##

Plugins[MG_PATH_$id_as]=$REPLY
Plugins[MG_PID_$id_as]=$reply[1]

##
## Support messages
##

if (( Zinit_Annex_Mg[enable-output] )) {
# Clear the messages-flag, for cleanness
Zinit_Annex_Mg[enable-output]=0

# Enable the output from this annex
# [Updated to disable via configuration]
if (( $+ZINIT_ANNNEX_MG_HUMBLE ))
then
IBSHOW_MESSAGES=0
else
IBSHOW_MESSAGES=1
fi
}

# Overwrite the outside parameters in order to introduce
# the actual object's ID.
ICE[id-as]=${id_as:-$___id} # cascade from ice to the phy-ID
___id=%$REPLY # overwrite the physical-ID
___ehid=$ICE[id-as] # handler ID – the id-as'' ice
___etid=%$REPLY # folder path (via preceding %)
ICE[teleid]=%$REPLY # folder path (via preceding %)

# Debug message.
if ((IBSHOW_MESSAGES));then
+zinit-message {pre}mg annex: {msg}Matched \
the miligram to its dir: \
{meta}$SID {ehi}→ {b}{file}${ICE[teleid]#%}
fi

return 0
}

# vim:ft=zsh:tw=80:sw=4:sts=4:et
27 changes: 27 additions & 0 deletions lib/annex/mg/functions/mg::cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env zsh
# -*- mode: sh;sh-indentation: 4;indent-tabs-mode: nil;sh-basic-offset: 4; -*-
# Copyright (c) 2020 Sebastian Gniazdowski

mg::cmd() {
# Set the base and typically useful options.
builtin emulate -L zsh -o extendedglob -o warncreateglobal \
-o typesetsilent -o noshortloops \
-o rcquotes

local cmd=$2
local -a args=($@[3,-1])
local -A cmds=(
build mg::cmd-build
extract mg::cmd-extract
load mg::cmd-load
ls mg::cmd-ls
)
if [[ -z $cmds[$cmd] ]];then
+zinit-message {pre}mg annex: {warn}unknown {cmd}mg\
{warn}subcommand given \({cmd}$cmd{warn}\)
return 1
fi

$cmds[$cmd] "$args[@]"
return $?
}
81 changes: 81 additions & 0 deletions lib/annex/mg/functions/mg::cmd-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env zsh
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# Copyright (c) 2023 Sebastian Gniazdowski

mg::cmd-build() {
# Set the base and typically useful options.
builtin emulate -L zsh -o extendedglob -o warncreateglobal \
-o typesetsilent -o noshortloops \
-o rcquotes
local tool=${XMG_TOOL:-appimagetool}
integer QRET

# -o - base output file name
# -v - set version
# -q - quiet
# --verbose verbose output
local -A Opts=(
-v "${$(git describe --tags)##[a-zA-Z-]##}"
)
builtin zparseopts -D -E -A Opts -K -- \
v q -verbose h -help -mv||return 7
Opts[-o]=${Opts[-o]:-$PWD:t-$Opts[-v].mg}

if (($+Opts[-h]||$+Opts[--help]));then
+zinit-message {pre}mg annex: {note}Usage:{rst}
return 0
fi

if ((!$+commands[$tool]));then
+zinit-message {pre}mg annex: {error}no {cmd}$tool \
{error}found, please install the relevant package \
\(via e.g.: {pkg}apt-get install $tool{error}\)
return 1
fi

+zinit-message {i} {pre}mg annex: {note}running command: \
{var}VERSION{note}={data}$Opts[-v] \
{cmd}appimagetool {opt}-v -n \
{b}{file}$Opts[-o]{note}{…}
LANG=C sleep 0.5

run-ait() {
local sed_=sed
(($+commands[gsed]))&&sed_=gsed
local SDESKTOP=$PWD:t.desktop
if [[ ! -e $SDESKTOP ]];then
command cp -vf $Plugins[MG_DIR]/share/desktop.tmpl $SDESKTOP
command $sed_ -i -r -e 's/\{name\}/'$PWD:t'/g' $SDESKTOP
command $sed_ -i -r -e 's/\{version\}/'$Opts[-v]'/g' $SDESKTOP
fi
command touch AppRun $PWD:t.png
command chmod +x AppRun
VERSION=$Opts[-v] ARCH="x86_64" "$1" \
${Opts[--verbose]+--verbose} \
-n $PWD \
$Opts[-o]
QRET=$?
}
if (($+Opts[-q]));then
run-ait $tool &>/dev/null
else
run-ait $tool
fi
builtin unset -f run-ait

if ((!$QRET));then
+zinit-message {i} {pre}mg-annex: {note}the build \
was {hi}successfull{nb}{note}!
else
+zinit-message {i} {pre}mg-annex: {error}the build \
{b}{error}failed{error}!
return QRET
fi

if ((!$QRET && $+Opts[--mv]));then
+zinit-message {i} {pre}mg-annex: {note}moving the output \
file to {data}plugins{note} dir \
\({b}{dir}$ZINIT[PLUGINS_DIR]{nb}{note}\){…}
command mv -v -- $Opts[-o] $ZINIT[PLUGINS_DIR]
fi
}
88 changes: 88 additions & 0 deletions lib/annex/mg/functions/mg::cmd-extract
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env zsh
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4;-*-
# Copyright (c) 2023 Sebastian Gniazdowski

mg::cmd-extract() {
# Set the base and typically useful options.
builtin emulate -L zsh -o extendedglob -o warncreateglobal \
-o typesetsilent -o noshortloops \
-o rcquotes
local STOOL=${XMG_TOOL:-appimagetool} SID=${${1#@}%%(.mg|/##)##}
integer QRET
local -a match mbegin mend
local MATCH SPATH
integer MBEGIN MEND
SPATH=($ZINIT[PLUGINS_DIR]/(#i)($SID)([v0-9.-]##)#.mg)
SPATH=${${(O@n)SPATH}[1]}

# -o - output dir name
# -v/--verbose verbose output
# -p/--plg out in zinit plugin dir
# -h/--help usage info
# -q/--quiet be quiet
local -A Opts=(
--output $SID:r:t
)
builtin zparseopts -D -E -A Opts -K -- \
q -quiet o: -output: p -plg v -verbose h -help||return 7
mg::opt-cascade Opts -q --quiet -v --verbose -o --output -h --help -p --plg
if (($+Opts[-p]));then
if [[ -z ${Opts[-o]##/*} ]];then
Opts[-o]=$ZINIT[PLUGINS_DIR]/$Opts[-o]:t
else
Opts[-o]=$ZINIT[PLUGINS_DIR]/$Opts[-o]
fi
fi
Opts[-o]=${Opts[-o]:P}

if (($+Opts[-h]));then
+zinit-message {pre}mg annex: {note}Usage:{rst}
return 0
fi

if ((!$+commands[$STOOL]));then
(($+Opts[-q]))||+zinit-message {pre}mg annex: {w}{warn}no {cmd}$STOOL \
{warn}command found, the {b}{warn}extraction will proceed \
{nb}{warn}however please install the relevant package \
\(via e.g.: {pkg}apt-get install $STOOL{warn}\)
fi

if [[ -e $Opts[-o] ]];then
(($+Opts[-q]))||+zinit-message {pre}mg annex: {e}{error}the \
file/dir {file}$Opts[-o] {error}already exists{…} exiting{…}
return 8
fi

command mkdir -p -- $Opts[-o]:h
(($+Opts[-q]))||+zinit-message {i} {pre}mg annex: {note}running command: \
./{cmd}$SPATH:t {opt}--appimage-extract{note}{…}
LANG=C sleep 0.5

run-aie() {
local SDIR=$(mktemp -d)
builtin cd -q -- $SDIR
trap 'builtin cd -q -- "$OLDPWD"' EXIT
trap 'builtin cd -q -- "$OLDPWD";return 1' INT TERM QUIT
if (($1));then
VERSION=$Opts[-v] "$SPATH" --appimage-extract
else
VERSION=$Opts[-v] "$SPATH" --appimage-extract&>!/dev/null
fi
QRET+=$?
command mv -f ${${${+Opts[-v]}:#0}:+-v} -- squashfs-root $Opts[-o]|
QRET+=$?
return QRET
}
run-aie $+Opts[-v] $STOOL

builtin unset -f run-aie

if ((!$QRET));then
(($+Opts[-q]))||+zinit-message {i} {pre}mg-annex: {note}the extraction \
was {hi}successfull{nb}{note}!
else
(($+Opts[-q]))||+zinit-message {i} {pre}mg-annex: {warn}the extraction \
{b}{error}failed{error}!
fi
return QRET
}
20 changes: 20 additions & 0 deletions lib/annex/mg/functions/mg::err-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env zsh
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4;-*-

# Copyright (c) 2023 Sebastian Gniazdowski

mg::err-msg() {
local bad_id=$1 bad_id2=$2 bad_tele=$3 is_pack=$4
local -a msgs
msgs=(
${bad_not_mg:+"the id doesn't have .mg suffix and no mg'' ice given"}
${bad_id:+"the ID contains a slash"}
${bad_id2:+"the ID looks like a snippet ID (URL)"}
${is_pack:+"the pack'' ice have been given"}
)

+zinit-message {pre}zmg annex: \
{msg}Skipping the ID: {meta2}$id{msg} \
"(reason(s): ${(j:, and also :)msgs}).{rst}"
return 0
}
Loading
Loading