pgsh.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. function pgsh() {
  2. this.prompt = '<span style="color:purple">pgs </span><span style="color:green">$ </span>'
  3. this.welcome = ''
  4. this.commands = {
  5. 'about': {
  6. 'help': 'Author Information\nUsage: about',
  7. 'run': function(args) {
  8. if (args.length > 0) { return this.help }
  9. return 'Site by Weiyi Lou ' + new Date().getFullYear()
  10. }
  11. },
  12. 'clear': {
  13. 'help': 'Clears the screen\nUsage: clear',
  14. 'run' : function() { return 'clear' }
  15. },
  16. 'version': {
  17. 'help': 'Shell Information\nUsage: version',
  18. 'run': function(args) {
  19. if (args.length > 0) { return this.help }
  20. return 'Parsley Gardens Shell (pgsh) 1.0.0. Built with <a target="_blank" href="http://riotjs.com/">Riot.js</a>'
  21. }
  22. },
  23. 'git': {
  24. 'help': 'Link to Code Repository\nUsage: git',
  25. 'run': function(args) {
  26. if (args.length > 0) { return this.help }
  27. return 'Self-Hosted Code Repository at <a target="_blank" href="https://code.parsleygardens.net/explore/projects">code.parsleygardens.net</a>'
  28. }
  29. },
  30. 'hello': {
  31. 'help': 'Usage: hello [name]',
  32. 'run': function(args) {
  33. address = args.join(' ').trim()
  34. if (address.length == 0) {
  35. return 'Hello to you too'
  36. } else if (address == 'pgsh') {
  37. return 'Hello human'
  38. } else {
  39. return 'My name is not "' + address + '"'
  40. }
  41. }
  42. },
  43. 'magic': {
  44. 'help': 'Link to Artist\nUsage: magic',
  45. 'run': function(args) {
  46. if (args.length > 0) { return this.help }
  47. return 'Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
  48. }
  49. },
  50. 'su': {
  51. 'help': 'Substitute as root user for Phenomenal Cosmic Power\nUsage: su',
  52. 'run': function(args, context) {
  53. if (args.length > 0) { return this.help }
  54. var output = ''
  55. if (!context.su) {
  56. context.oldprompt = context.prompt
  57. context.prompt = '<span style="color:purple">root </span><span style="color:red">% </span>'
  58. context.su = true
  59. output = 'With Great Power comes Great'
  60. }
  61. return output
  62. }
  63. },
  64. 'exit': {
  65. 'help': 'Usage: exit',
  66. 'run': function(args, context) {
  67. if (args.length > 0) { return this.help }
  68. var output = 'Close browser window to exit'
  69. if (context.su) {
  70. context.prompt = context.oldprompt
  71. context.su = false
  72. output = ''
  73. }
  74. return output
  75. }
  76. },
  77. 'help': {
  78. 'help': 'List all commands or view information for a command\nUsage: help [command]',
  79. 'run': function(args, context) {
  80. command = args.join(' ').trim()
  81. if (command in context.commands) {
  82. return context.commands[command].help
  83. } else {
  84. var output = (command) ? 'Command not found: ' + command + '\n' : ''
  85. var commands = [];
  86. for(var name in context.commands) {
  87. if (name !== 'Parent') { commands.push(name) }
  88. }
  89. output += 'Available commands:\n' + commands.sort().join(' ')
  90. return output
  91. }
  92. }
  93. }
  94. }
  95. this.process = function(input) {
  96. var parts = input.trim().split(' ')
  97. // First word is the command, all others are arguments.
  98. var command = parts.splice(0, 1)
  99. var args = parts
  100. var output = ''
  101. if (command in this.commands) {
  102. var shell = this
  103. output += this.commands[command].run(args, shell)
  104. }
  105. return output
  106. }
  107. }
  108. var pgsh = new pgsh()