Skip to content

Instantly share code, notes, and snippets.

@rusty-snake
Last active July 2, 2019 09:39
Show Gist options
  • Save rusty-snake/86e1718849ed6246a99547df4953ebb8 to your computer and use it in GitHub Desktop.
Save rusty-snake/86e1718849ed6246a99547df4953ebb8 to your computer and use it in GitHub Desktop.
The difference between a system language and a scripting language.
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2019 rusty-snake (https://github.com/rusty-snake) <print_hello_world+License@protonmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from os import listdir
def ls():
for file in listdir():
print(file)
def prompt():
cmd = input("> ").strip()
if cmd == "ls":
ls()
elif cmd == "exit":
exit()
while True:
prompt()
/*
* MIT License
*
* Copyright (c) 2019 rusty-snake (https://github.com/rusty-snake) <print_hello_world+License@protonmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
use std::fs;
use std::io;
use std::process::exit;
// Runing:
// install rust (https://www.rust-lang.org/tools/install)
// compile with `rustc --edition=2018 -o prompt prompt.rs
// run with `./prompt`
fn main() {
loop {
prompt();
}
}
fn ls() {
for file in fs::read_dir(".").unwrap() {
println!("{}", file.unwrap().file_name().to_str().unwrap());
}
}
fn prompt() {
eprint!("> ");
let mut cmd = String::new();
io::stdin().read_line(&mut cmd).unwrap();
cmd = cmd.trim().to_string();
if cmd == "ls" {
ls();
} else if cmd == "exit" {
exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment