top | item 40364057

(no title)

c6401 | 1 year ago

For my personal needs, when it's not used as a build system but for collecting some shell functions in a file, I've completely switched to a combination of xonsh/python-fire and never looked back. Xonsh looks a bit weird, but it's superfast to write, and I always can read it perfectly. A messy example - one of my local scripts:

../bin/ok:

    #!/usr/bin/env xonsh
    """
    $> ok android shell
    $> ok android ssh
    $> ok android sshd
    $> ok android sms
    """
    import fire as _fire

    class android:
        ip = '...;

        def shell(self):
            adb connect f'{self.ip}:5555'
            adb shell

        def sshd(self):
            adb connect f'{self.ip}:5555'
            adb shell input keyevent 26
            adb shell input swipe 500 800 500 300 200
            sleep 1
            adb shell am start -n com.termux/.app.TermuxActivity
            adb shell input text "sshd"
            adb shell input keyevent 66
            adb shell input text "exit"
            adb shell input keyevent 66

        def ssh(self):
            ssh -p 8022 f'user@{self.ip}'

        def sms(self):
            result = $(ssh -p 8022 f'user@{self.ip}' termux-sms-list -l 20 | jq ".[].body")
            print(result)
            def long_echo(): print(result)
            @(long_echo) | llm -m llama3 -s 'please translate messages to English, quote the original messages too'

    if __name__ == '__main__':
        _fire.Fire()

discuss

order

No comments yet.