Created
August 5, 2020 19:45
-
-
Save Interfiber/16c5794007d6ae28c0bb6b5f1ac0fd6b to your computer and use it in GitHub Desktop.
A version of ls that adds file and file icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs; | |
use std::env; | |
fn printIcon(fileType: String, icon: String, file: String){ | |
if file.contains(&fileType){ | |
println!("{} {}", icon, file); | |
} | |
} | |
fn main() { | |
let args: Vec<String> = env::args().collect(); | |
let mut paths = fs::read_dir(".").unwrap(); | |
if args.len() > 1 { | |
paths = fs::read_dir(args[1].to_string()).unwrap(); | |
} | |
// folder | |
// file | |
// config file | |
// rust file | |
// | |
for path in paths { | |
let currentPath = path.unwrap().path().display().to_string().replace("./", ""); | |
if currentPath.contains("Cargo.toml"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".lock"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains("_config.yml"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains("requirments.txt"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".py"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".txt"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".rs"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains("gulpfile.js"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".js"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".rb"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".github"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".git"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".json"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains("package.json"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains("node_modules") || currentPath.contains(".npm"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".java"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".html") || currentPath.contains(".htm") { | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".cpp") || currentPath.contains(".cc"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".kt"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".go"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".lua"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".vscode"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".app"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".scss"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".swift"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".vim"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".ts"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".md") || currentPath.contains(".markdown"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".css"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".sh") || currentPath.contains(".bash") || currentPath.contains(".command") || currentPath.contains(".fish") || currentPath.contains(".bashrc") || currentPath.contains(".bash_profile") || currentPath.contains(".zshrc") || currentPath.contains(".zsh"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains("Dockerfile"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains("test"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".out") || currentPath.contains(".a"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".blend"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".erb"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".groovy"){ | |
println!(" {}", currentPath); | |
} | |
else if currentPath.contains(".scala"){ | |
println!(" {}", currentPath); | |
} | |
else { | |
println!(" {}", currentPath); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment