├── README.md └── vish.v /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | Please use [dvwallin/vlsh](https://github.com/dvwallin/vlsh) instead. 3 | -------------------------------------------------------------------------------- /vish.v: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | import os 4 | import term 5 | 6 | #include 7 | 8 | fn handler(signum os.Signal) { 9 | println("Got signal $signum") 10 | println('') 11 | exit(0) 12 | } 13 | 14 | fn main() { 15 | os.signal_opt(os.Signal.hup, handler) ? 16 | os.signal_opt(os.Signal.quit, handler) ? 17 | for { 18 | abvwd := term.colorize(term.bold, '$os.getwd()').replace('$os.home_dir()', '~') 19 | mut stdin := (os.input_opt('$abvwd\n➜ ') or { 20 | exit(1) 21 | '' 22 | }).split(' ') 23 | match stdin[0] { 24 | 'cd' { 25 | os.chdir(stdin[1]) or { 26 | println("cd: error: no such file or directory") 27 | } 28 | } 29 | 'clear' { 30 | term.clear() 31 | } 32 | 'chmod' { 33 | if os.exists(stdin[2]) { 34 | os.chmod(stdin[2], ('0o' + stdin[1]).int()) ? 35 | } else { 36 | println('chmod: error: path does not exist') 37 | } 38 | } 39 | 'cp' { 40 | if os.exists(stdin[1]) { 41 | if os.exists(stdin[2]) { 42 | println('cp: error: destination path exists, use ocp to override') 43 | } else { 44 | os.cp(stdin[1], stdin[2]) ? 45 | } 46 | } else { 47 | println('cp: error: source path does not exist') 48 | } 49 | } 50 | 'ocp' { 51 | if os.exists(stdin[1]) { 52 | os.cp(stdin[1], stdin[2]) ? 53 | } else { 54 | println('ocp: error: source path does not exist') 55 | } 56 | } 57 | 'exit' { 58 | exit(0) 59 | } 60 | 'help' { 61 | println('cd Change to provided directory. 62 | chmod Change file/dir access attributes and permissions. 63 | clear Clears the screen. 64 | cp Copy source file/dir to destination. 65 | echo Print entered message. 66 | exit Exit the shell. 67 | help Displays this message. 68 | ls List all files and subdirectories in current directory. 69 | mkd Creates new directory. 70 | ocp Override existing destination for cp. 71 | rm Removes file. 72 | rmd Removes directory.') 73 | } 74 | 'ls' { 75 | ls := os.ls('.') ?.join(' ') 76 | println(ls) 77 | } 78 | 'mkd' { 79 | os.mkdir_all(stdin[1]) ? 80 | } 81 | 'rm' { 82 | if os.exists(stdin[1]) { 83 | if os.is_dir(stdin[1]) { 84 | println("rm: error: cannot remove '" + stdin[1] + "': Is a directory") 85 | } else { 86 | os.rm(stdin[1]) ? 87 | } 88 | } else { 89 | println("rm: error: cannot remove'" + stdin[1] + "': Path does not exist") 90 | } 91 | } 92 | 'rmd' { 93 | if os.exists(stdin[1]) { 94 | os.rmdir(stdin[1]) ? 95 | } else { 96 | println("rm: error: cannot remove'" + stdin[1] + "': Path does not exist") 97 | } 98 | } 99 | 'echo' { 100 | stdin.delete(0) 101 | println(stdin.join(' ')) 102 | } 103 | else { 104 | println('command not found: ' + stdin[0]) 105 | } 106 | } 107 | } 108 | exit(0) 109 | } 110 | --------------------------------------------------------------------------------