[PATCHES] improve extensions support

HacKan hackan at gmail.com
Mon Feb 6 22:47:28 CET 2017


Woops, that's true. It always uses the internal cmd_show().

But adding that line, and even the bottom cmd_show, isn't a good idea.
We should do an iteration (and I should've done that).

Give me a moment and I sending a patch for that. The basic idea would be:

PROGRAM="${0##*/}"
COMMANDS=( "$1" "show" )
shift

for COMMAND in "${COMMANDS[@]}"; do

    # Check if command is an extension
    check_extension_and_load "$COMMAND" "$@" && exit 0

    # Check if command is internal command
    #
    # Internal commands must begin with cmd_ and named like cmd_command
    # Multiname functions such as delete=remove=rm can be done like 
    #  cmd_remove() { cmd_delete; }
    #  cmd_rm() { cmd_delete; }
    # Others like help=--help are handled by cmd_internal() as long as a function 
    # exists without --
    # Bear in mind that aliases are not expanded by eval (used in cmd_internal), 
    # so creating functions is a better way to go.
    cmd_internal "$COMMAND" "$@" && exit 0

done

I wrote that from the top of my head, so it requires some testing.

Thanks!

On 02/06/2017 06:33 PM, Lars Flitter wrote:
> Hi,
>
> I like the idea of overriding the built in pass commands and
> functions. I was looking for a way to override the clip function used
> in the show command. With this approach overridden functions are
> contained within a single extension, not interfering with other
> extensions that might rely on the original function.
>
> The way cmd_internal calls the cmd_-functions allows for a nice way to
> alias the multi-name functions.
>
> The only thing I'm missing is built-in support to override the
> implicit show command with an extension.
>
> This could be achieved by adding
> check_extension_and_load show "$@" && exit 0
>
> before the final
> cmd_show "$@"
>
> Regards,
> Lars
>
> On 06.02.2017 17:40, HacKan wrote:
>> Hello there! I spent the last few days playing around with pass, so I
>> forked it [1] and changed the way it handles extensions, because I
>> wanted to allow extensions to override internal commands. I.E. if
>> someone wants to modify the way /generate/ works, there's no need to
>> touch pass's core but simply create an extension named /generate.bash
>> /and that's all/./
>>
>> Here's the rough changes list:
>>
>>   * Modified the way commands are interpreted in the script: replaced
>>     the switch case selection to a more flexible eval'd one.
>>   * Changed how extensions are handled: now extensions are loaded first,
>>     before interpreting the command as an internal command. This allows
>>     extensions to override internal commands. A helper function is
>>     provided so that an overridden function can still be called from the
>>     extension.
>>   * Issuing help command now shows help from the extensions if they
>>     implement a function named help_{extension name}(). Otherwise, it
>>     will list enabled extensions as commands.
>>
>> This keeps backwards compatibility at 100%, existing extensions are too
>> 100% compatible. So for the final user these patches doesn't have any
>> effect at all.
>>
>> Patches and signed hashes are attached.
>>
>> Also, I tested these and all tests passed (attached as
>> /tests-result.txt/). Note that tests must be fixed first (see /[PATCH]
>> Fixes for tests/ [2]).
>>
>> A sample /pass --help/ output with a couple of extensions I made is
>> attached (/help-example.txt/).
>>
>> Attachment list:
>> 0001-Changed-function-switch-based-on-parameters-by-a-mor.patch
>> 0002-Added-helper-override_function-to-enable-extensions-.patch
>> 0003-Modified-cmd_usage-to-show-extensions-usage-help-too.patch
>> 0004-Minor-bugfixes-in-cmd_usage-when-showing-extensions-.patch
>> 0005-Fixed-multiname-functions-parameters-were-not-being-.patch
>> 0006-Small-bugfix-in-usage-command.-Also-changed-spaces-f.patch
>> SHA512SUMS
>> SHA512SUMS.sig
>> help-example.txt
>> tests-result.txt
>>
>> Cheers!
>>
>> [1]: https://github.com/HacKanCuBa/passh
>> [2]:
>> https://lists.zx2c4.com/pipermail/password-store/2017-February/002727.html
>>
>>
>> -- 
>> HacKan || Iván
>> GPG: 0x35710D312FDE468B
>>
>>
>>
>> _______________________________________________
>> Password-Store mailing list
>> Password-Store at lists.zx2c4.com
>> https://lists.zx2c4.com/mailman/listinfo/password-store
>>
> _______________________________________________
> Password-Store mailing list
> Password-Store at lists.zx2c4.com
> https://lists.zx2c4.com/mailman/listinfo/password-store

-- 
HacKan || Iván
GPG: 0x35710D312FDE468B




More information about the Password-Store mailing list