KNOXDEV / scoop-backup

Backup your entire current scoop installation with one command
The Unlicense
60 stars 6 forks source link

fails handling scoop aliases with multiple lines #11

Closed phanirithvij2000 closed 2 years ago

phanirithvij2000 commented 2 years ago

Scoop aliases with multiple lines will generate a cli command with a single line and with no line seperators.

E.g.

An alias multiline manually edited (customized)

# Summary: alias script with multiple lines
write-host first line
write-host second line
write-host etc..
# Scoop-Backup's output for this alias
scoop alias add 'multiline' 'write-host first line write-host second line write-host etc..' 'alias script with multiple lines'

This is invalid.

So a possible fix might be handling newlines in powershell or encode/decode alias files to base64 (or some other format)

KNOXDEV commented 2 years ago

I don't immediately have a good idea. How would you go about creating a multi-line alias in the first place? Would you manually edit the scoop/config.json?

phanirithvij commented 2 years ago

In the config.json aliases dict has keys as the alias name and the alias script name as the value . The alias script is saved in the shims directory.

So I create a stub from cli scoop alias add myalias 'write-host myalias' 'description' and go and edit the shims/scoop-myalias.ps1

KNOXDEV commented 2 years ago

This is a little bit niche since it kinda seems like scoop barely supports multi line aliases in the first place, but alright.

In that case, the solution would probably be to back up the shim files themselves. They would need to be probably encoded as base64 and embedded into the restore script, which would redump them into the shim directory. It's a bit involved.

phanirithvij2000 commented 2 years ago

Yeah you're right, calling external commands in one line which the scoop alias provides is good enough. I think implementing alias files embedding is not really needed, just a good to have. I think this single line implementation is fine as of now, maybe just mention this issue, in this repo README. As multiline alias scripts are not supported by scoop alias add use external scripts as a workaround, which need to be separately backed up.

eg.

scoop alias add myalias 'powershell -file path/to/myalias.ps1' 'some alias'
# or some other command and file which handles the alias logic (.py, .lua, .sh, .exe, ... whatever)
scoop alias add magic 'python path/to/file/magic.py' 'some alias written in python'
scoop alias add magicwithargs 'python -c "import sys; print(sys.argv)" `$args' 'some alias written in python that accepts args'

EDIT: just use `$args as the argument to the external command. ~But as I'm not familiar with powershell, I'm unsure how to forward the command line arguments which are stored in $Args in the alias ps1 script scope to the external command. but that can't be that hard to figure out~