Add --insert option for shell userscript.

master
Harshad Sharma 7 years ago
parent d591f93551
commit 94d586317c

@ -9,6 +9,10 @@ parser.add_argument('-c',
action='store', action='store',
help='Command to execute.', help='Command to execute.',
default='') default='')
parser.add_argument('--insert',
action='store_true',
help='Type output into current tab?',
default=False)
@userscript @userscript
@ -17,8 +21,13 @@ def shell_command(request):
if not args.c: if not args.c:
request.send_text("Please specify a command: {} -c'uname -a' ".format(request.script_name)) request.send_text("Please specify a command: {} -c'uname -a' ".format(request.script_name))
return return
r = subprocess.check_output(args=args.c.split(' ')) r = subprocess.check_output(args=args.c, shell=True)
request.send_text(r) text = str(r, 'utf-8').strip()
if args.insert:
request.send_command('insert-text {}'.format(text))
# request.send_text(text)
else:
request.send_text(text)
if __name__ == '__main__': if __name__ == '__main__':

@ -6,13 +6,23 @@ import stat
REVIEW_TEMPLATE = """\ REVIEW_TEMPLATE = """\
Qutebrowser userscript {name!r} was installed at: Qutebrowser userscript {name!r} was installed at:
{userscripts_path!r} {userscripts_path!r}
You can try it out by running the command: Try it out by running the command:
:spawn --userscript {name} :spawn --userscript {name}
Bind the command to a keystroke with:
:bind KEYS spawn --userscript {name} OPTIONAL-ARGUMENTS
examples:
- :bind kk spawn --userscript debug --kaboom
Use this by typing "kk" in normal mode, not fun :P
- :bind ,dt spawn --userscript shell -c"date" --insert
Inserts current date in active tab.
Warning: Enclose your provided arguments and options in quotes and
always test your command passed to `shell -c""` in the shell.
""" """
LOADER_TEMPLATE = """\ LOADER_TEMPLATE = """\

Loading…
Cancel
Save