Skip to content
Draft
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
10 changes: 10 additions & 0 deletions addons/gdshell/commands/autorun.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends GDShellCommand


func _main(_argv: Array, _data) -> CommandResult:
output("Autorun here...")
#var x = await input("gimme text: ") # TODO input() blocks all following input
#output("hi %s" % x)
#execute("echo hi")
# execute("gdfetch")
return CommandResult.new()
1 change: 1 addition & 0 deletions addons/gdshell/commands/autorun.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dhwdbfprk0w34
35 changes: 15 additions & 20 deletions addons/gdshell/commands/default_commands/alias.gd
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
extends GDShellCommand


func _init():
COMMAND_AUTO_ALIASES = {
"unalias": "alias -r",
}


func _main(argv: Array, data) -> Dictionary:
func _main(argv: Array, data) -> CommandResult:
var success: bool

if not argv.size() > 2:
output("Not enough arguments")
return {"error": 1, "error_string": "Not enough arguments"}
return CommandResult.new(1, "Not enough arguments")

if "-r" in argv[1] or "--remove" in argv[1]:
success = _PARENT_PROCESS._PARENT_GDSHELL.command_db.remove_alias(argv[2])
if success:
output("Alias '%s' removed" % argv[2])
return DEFAULT_COMMAND_RESULT
_PARENT_COMMAND_RUNNER._PARENT_GDSHELL.command_db.remove_alias(argv[2])
return CommandResult.new()

success = _PARENT_PROCESS._PARENT_GDSHELL.command_db.add_alias(argv[1], argv[2])
if not success:
output("Could not add alias '%s'" % argv[1])
return {"error": 1, "error_string": "Could not add alias"}
_PARENT_COMMAND_RUNNER._PARENT_GDSHELL.command_db.add_alias(argv[1], argv[2])

output("Alias '%s' added" % argv[1])
return DEFAULT_COMMAND_RESULT
# output("Alias '%s' added" % argv[1])
return CommandResult.new()


func _get_command_auto_aliases() -> Dictionary:
return {
"unalias": "alias -r",
}


func _get_manual() -> String:
Expand Down Expand Up @@ -63,8 +58,8 @@ func _get_manual() -> String:
-Same as [i]alias -r print[/i]
""".format(
{
"COMMAND_NAME": COMMAND_NAME,
"COMMAND_AUTO_ALIASES": COMMAND_AUTO_ALIASES,
"COMMAND_NAME": _get_command_name(),
"COMMAND_AUTO_ALIASES": _get_command_auto_aliases(),
}
)
)
1 change: 1 addition & 0 deletions addons/gdshell/commands/default_commands/alias.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dqkp7k311c7qq
6 changes: 0 additions & 6 deletions addons/gdshell/commands/default_commands/autorun.gd

This file was deleted.

51 changes: 26 additions & 25 deletions addons/gdshell/commands/default_commands/bool.gd
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
extends GDShellCommand


const TRUE: Dictionary = {
"error": 0,
"data": "true",
}
const FALSE: Dictionary = {
"error": 1,
"error_string": "This is not an error, but false.",
"data": "false",
}
var TRUE: CommandResult = CommandResult.new(
0,
"",
true
)
var FALSE: CommandResult = CommandResult.new(
1,
"This is not an error, but false from bool command.",
false
)


func _init():
COMMAND_AUTO_ALIASES = {
"true": "bool -t",
"false": "bool -f",
"random": "bool -r",
}


func _main(argv: Array, data) -> Dictionary:
func _main(argv: Array, _data) -> CommandResult:
if not argv.size() > 1:
return TRUE

Expand All @@ -33,11 +26,19 @@ func _main(argv: Array, data) -> Dictionary:
randomize()
return TRUE if randi() % 2 else FALSE
_:
return {
"error": ERR_INVALID_PARAMETER,
"error_string": "Parameter '%s' not recognized" % argv[1],
"data": null,
}
return CommandResult.new(
ERR_INVALID_PARAMETER,
"Parameter '%s' not recognized" % argv[1],
null
)


func _get_command_auto_aliases():
return {
"true": "bool -t",
"false": "bool -f",
"random": "bool -r",
}


func _get_manual() -> String:
Expand Down Expand Up @@ -78,8 +79,8 @@ func _get_manual() -> String:
Same as: random && echo "true" || echo "false"
""".format(
{
"COMMAND_NAME": COMMAND_NAME,
"COMMAND_AUTO_ALIASES": COMMAND_AUTO_ALIASES,
"COMMAND_NAME": _get_command_name(),
"COMMAND_AUTO_ALIASES": _get_command_auto_aliases(),
}
)
)
1 change: 1 addition & 0 deletions addons/gdshell/commands/default_commands/bool.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://0jqep47mskax
20 changes: 10 additions & 10 deletions addons/gdshell/commands/default_commands/clear.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
extends GDShellCommand


func _init():
COMMAND_AUTO_ALIASES = {
"cls": "clear",
}


func _main(_argv: Array, _data) -> Dictionary:
func _main(_argv: Array, _data) -> CommandResult:
# Truly unbelieveable programming skills
get_ui_handler_rich_text_label().clear()
return DEFAULT_COMMAND_RESULT
return CommandResult.new()


func _get_command_auto_aliases():
return {
"cls": "clear",
}


func _get_manual() -> String:
Expand All @@ -33,8 +33,8 @@ func _get_manual() -> String:
-Same as [i]clear[/i]
""".format(
{
"COMMAND_NAME": COMMAND_NAME,
"COMMAND_AUTO_ALIASES": COMMAND_AUTO_ALIASES,
"COMMAND_NAME": _get_command_name(),
"COMMAND_AUTO_ALIASES": _get_command_auto_aliases(),
}
)
)
1 change: 1 addition & 0 deletions addons/gdshell/commands/default_commands/clear.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cy2ajeeqr4rvm
8 changes: 4 additions & 4 deletions addons/gdshell/commands/default_commands/echo.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends GDShellCommand


func _main(argv: Array, data) -> Dictionary:
func _main(argv: Array, data) -> CommandResult:
var out: String = ""

if data != null:
Expand All @@ -13,7 +13,7 @@ func _main(argv: Array, data) -> Dictionary:
output(out)

@warning_ignore("incompatible_ternary")
return {"data": null if out.is_empty() else out}
return CommandResult.new(OK, "", null if out.is_empty() else out)


func _get_manual() -> String:
Expand All @@ -40,8 +40,8 @@ SYNOPSIS
-Prints Hello 1 World!
""".format(
{
"COMMAND_NAME": COMMAND_NAME,
"COMMAND_AUTO_ALIASES": COMMAND_AUTO_ALIASES,
"COMMAND_NAME": _get_command_name(),
"COMMAND_AUTO_ALIASES": _get_command_auto_aliases(),
}
)
)
1 change: 1 addition & 0 deletions addons/gdshell/commands/default_commands/echo.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dk2m8fw8cijpa
20 changes: 10 additions & 10 deletions addons/gdshell/commands/default_commands/gdfetch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ const LOGO: String = (
)


func _init():
COMMAND_AUTO_ALIASES = {
"neofetch": "gdfetch --i-am-a-linux-nerd-and-tried-to-use-neofetch",
}


func _main(argv: Array, data) -> Dictionary:
func _main(argv: Array, data) -> CommandResult:
var info: Dictionary = get_info()

if "--i-am-a-linux-nerd-and-tried-to-use-neofetch" in argv:
Expand All @@ -50,7 +44,7 @@ func _main(argv: Array, data) -> Dictionary:
if not ("-s" in argv or "--silent" in argv):
output(construct_output(LOGO, info), false)

return {"data": info}
return CommandResult.new(0, "", info)


func construct_output(graphics: String, info: Dictionary, skip_lines: int = 3) -> String:
Expand Down Expand Up @@ -85,6 +79,12 @@ static func get_info() -> Dictionary:
}


func _get_command_auto_aliases():
return {
"neofetch": "gdfetch --i-am-a-linux-nerd-and-tried-to-use-neofetch",
}


func _get_manual() -> String:
return (
"""
Expand Down Expand Up @@ -116,8 +116,8 @@ func _get_manual() -> String:
Can be used as a input for other commands when called silently.
""".format(
{
"COMMAND_NAME": COMMAND_NAME,
"COMMAND_AUTO_ALIASES": COMMAND_AUTO_ALIASES,
"COMMAND_NAME": _get_command_name(),
"COMMAND_AUTO_ALIASES": _get_command_auto_aliases(),
}
)
)
1 change: 1 addition & 0 deletions addons/gdshell/commands/default_commands/gdfetch.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dpionqq57kuh3
32 changes: 16 additions & 16 deletions addons/gdshell/commands/default_commands/man.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ const LIST_FLAGS: Array[String] = ["l", "L", "list", "LIST"]
const SILENT_FLAGS: Array[String] = ["s", "S", "silent", "SILENT"]


func _init():
COMMAND_AUTO_ALIASES = {
"manual": "man",
"help": "man",
}


func _main(argv: Array, _data) -> Dictionary:
func _main(argv: Array, _data) -> CommandResult:
if not argv.size() > 1:
output("What manual page do you want? For example, try '[b]man man[/b]'\nTo see the list of all commands run '[b]man --list[/b]'")
return DEFAULT_COMMAND_RESULT
return CommandResult.new()

var options: Dictionary = GDShellCommand.argv_parse_options(argv, true, false)

if LIST_FLAGS.any(func(option): return option in options): # If any LIST_FLAG is in options
output("[b][color=AQUAMARINE]Available GDShell commands:[/color][/b]")
for command_name in _PARENT_PROCESS._PARENT_GDSHELL.command_db.get_all_command_names():
for command_name in _PARENT_COMMAND_RUNNER._PARENT_GDSHELL.command_db.get_all_command_names():
output("[color=BISQUE]%s[/color]" % command_name)

if not argv.size() > options.keys().size() + 1:
return DEFAULT_COMMAND_RESULT
return CommandResult.new()

var manual: String = ""
for i in range(1, argv.size()): # first non-option arg
Expand All @@ -34,17 +27,17 @@ func _main(argv: Array, _data) -> Dictionary:
break

if manual.is_empty():
return {"error": 1, "error_string": "No manual", "data": null}
return CommandResult.new(1, "No manual", null)

if not SILENT_FLAGS.any(func(option): return option in options): # If NOT any LIST_FLAG is in options
var line: int = get_ui_handler_rich_text_label().get_line_count()
output(manual)
get_ui_handler_rich_text_label().call_deferred(&"scroll_to_line", line)
return {"data": manual}
return CommandResult.new(0, "", manual)


func get_command_manual(command_name: String) -> String:
var command_db: GDShellCommandDB = _PARENT_PROCESS._PARENT_GDSHELL.command_db
var command_db: GDShellCommandDB = _PARENT_COMMAND_RUNNER._PARENT_GDSHELL.command_db
# unalias the name
while true:
if not command_name in command_db._aliases:
Expand All @@ -67,6 +60,13 @@ func get_command_manual(command_name: String) -> String:
return manual


func _get_command_auto_aliases() -> Dictionary:
return {
"manual": "man",
"help": "man",
}


func _get_manual() -> String:
return (
"""
Expand All @@ -90,8 +90,8 @@ func _get_manual() -> String:
-Prints the manual for the [i]man[/i] command
""".format(
{
"COMMAND_NAME": COMMAND_NAME,
"COMMAND_AUTO_ALIASES": COMMAND_AUTO_ALIASES,
"COMMAND_NAME": _get_command_name(),
"COMMAND_AUTO_ALIASES": _get_command_auto_aliases(),
}
)
)
1 change: 1 addition & 0 deletions addons/gdshell/commands/default_commands/man.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dwjw45cqys264
Loading