mirror of
https://github.com/uutils/coreutils
synced 2024-11-05 14:21:32 +00:00
Add the first four utils
This commit is contained in:
parent
d4e96b33e3
commit
9653ed81a2
8 changed files with 316 additions and 5 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build/*
|
4
LICENSE
4
LICENSE
|
@ -1,6 +1,4 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 uutils
|
||||
Copyright (c) Jordi Boggiano
|
||||
|
||||
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
|
||||
|
|
10
Makefile
Normal file
10
Makefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
build:
|
||||
rm -rf build
|
||||
mkdir build
|
||||
# run through the shell since make acting up on windows
|
||||
sh -c 'rustc --out-dir build/ false/false.rs'
|
||||
sh -c 'rustc --out-dir build/ printenv/printenv.rs'
|
||||
sh -c 'rustc --out-dir build/ true/true.rs'
|
||||
sh -c 'rustc --out-dir build/ yes/yes.rs'
|
||||
|
||||
.PHONY: build
|
141
README.md
141
README.md
|
@ -1,2 +1,139 @@
|
|||
coreutils
|
||||
=========
|
||||
uutils coreutils
|
||||
================
|
||||
|
||||
uutils is an attempt at writing universal (as in cross-platform) CLI
|
||||
utils in [Rust](http://rust-lang.org). This repo is to aggregate the GNU
|
||||
coreutils rewrites.
|
||||
|
||||
Why?
|
||||
----
|
||||
|
||||
Many GNU, linux and other utils are pretty awesome, and obviously
|
||||
[some](http://gnuwin32.sourceforge.net) [effort](http://unxutils.sourceforge.net)
|
||||
has been spent in the past to port them to windows. However those projects
|
||||
are either old, abandonned, hosted on CVS, written in platform-specific C, etc.
|
||||
|
||||
Rust provides a good platform-agnostic way of writing systems utils that are easy
|
||||
to compile anywhere, and this is as good a way as any to try and learn it.
|
||||
|
||||
To do
|
||||
-----
|
||||
|
||||
- base64
|
||||
- basename
|
||||
- cat
|
||||
- chcon
|
||||
- chgrp
|
||||
- chmod
|
||||
- chown-core
|
||||
- chown
|
||||
- chroot
|
||||
- cksum
|
||||
- comm
|
||||
- copy
|
||||
- cp-hash
|
||||
- cp
|
||||
- csplit
|
||||
- cut
|
||||
- date
|
||||
- dd
|
||||
- df
|
||||
- dircolors
|
||||
- dirname
|
||||
- du
|
||||
- echo
|
||||
- env
|
||||
- expand
|
||||
- expr
|
||||
- extent-scan
|
||||
- factor
|
||||
- find-mount-point
|
||||
- fmt
|
||||
- fold
|
||||
- getlimits
|
||||
- group-list
|
||||
- groups
|
||||
- head
|
||||
- hostid
|
||||
- hostname
|
||||
- id
|
||||
- install
|
||||
- join
|
||||
- kill
|
||||
- lbracket
|
||||
- libstdbuf
|
||||
- link
|
||||
- ln
|
||||
- logname
|
||||
- ls-dir
|
||||
- ls-ls
|
||||
- ls-vdir
|
||||
- ls
|
||||
- make-prime-list
|
||||
- md5sum
|
||||
- mkdir
|
||||
- mkfifo
|
||||
- mknod
|
||||
- mktemp
|
||||
- mv
|
||||
- nice
|
||||
- nl
|
||||
- nohup
|
||||
- nproc
|
||||
- numfmt
|
||||
- od
|
||||
- operand2sig
|
||||
- paste
|
||||
- pathchk
|
||||
- pinky
|
||||
- pr
|
||||
- printf
|
||||
- prog-fprintf
|
||||
- ptx
|
||||
- pwd
|
||||
- readlink
|
||||
- realpath
|
||||
- relpath
|
||||
- remove
|
||||
- rm
|
||||
- rmdir
|
||||
- runcon
|
||||
- seq
|
||||
- setuidgid
|
||||
- shred
|
||||
- shuf
|
||||
- sleep
|
||||
- sort
|
||||
- split
|
||||
- stat
|
||||
- stdbuf
|
||||
- stty
|
||||
- sum
|
||||
- sync
|
||||
- tac-pipe
|
||||
- tac
|
||||
- tail
|
||||
- tee
|
||||
- test
|
||||
- timeout
|
||||
- touch
|
||||
- tr
|
||||
- truncate
|
||||
- tsort
|
||||
- tty
|
||||
- uname-arch
|
||||
- uname-uname
|
||||
- uname
|
||||
- unexpand
|
||||
- uniq
|
||||
- unlink
|
||||
- uptime
|
||||
- users
|
||||
- wc
|
||||
- who
|
||||
- whoami
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
uutils are licensed under the MIT License - see the `LICENSE` file for details
|
||||
|
|
14
false/false.rs
Normal file
14
false/false.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
#[link(name="false", vers="1.0.0", author="Seldaek")];
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
std::os::set_exit_status(1);
|
||||
}
|
77
printenv/printenv.rs
Normal file
77
printenv/printenv.rs
Normal file
|
@ -0,0 +1,77 @@
|
|||
#[link(name="printenv", vers="1.0.0", author="Seldaek")];
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/* last synced with: printenv (GNU coreutils) 8.13 */
|
||||
|
||||
extern mod extra;
|
||||
|
||||
use std::os;
|
||||
use std::io::stderr;
|
||||
use extra::getopts::*;
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
let program = copy args[0];
|
||||
let opts = ~[
|
||||
groups::optflag("0", "null", "end each output line with 0 byte rather than newline"),
|
||||
groups::optflag("h", "help", "display this help and exit"),
|
||||
groups::optflag("V", "version", "output version information and exit"),
|
||||
];
|
||||
let matches = match groups::getopts(args.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
stderr().write_line("Invalid options");
|
||||
stderr().write_line(fail_str(f));
|
||||
os::set_exit_status(1);
|
||||
return
|
||||
}
|
||||
};
|
||||
if opts_present(&matches, [~"h", ~"help"]) {
|
||||
println("printenv 1.0.0");
|
||||
println("");
|
||||
println("Usage:");
|
||||
println(fmt!(" %s [VARIABLE]... [OPTION]...", program));
|
||||
println("");
|
||||
print(groups::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts));
|
||||
return;
|
||||
}
|
||||
if opts_present(&matches, [~"V", ~"version"]) {
|
||||
println("printenv 1.0.0");
|
||||
return;
|
||||
}
|
||||
let mut separator = "\n";
|
||||
if opts_present(&matches, [~"0", ~"null"]) {
|
||||
separator = "\x00";
|
||||
};
|
||||
|
||||
exec(matches.free, separator);
|
||||
}
|
||||
|
||||
pub fn exec(args: ~[~str], separator: &str) {
|
||||
if args.is_empty() {
|
||||
let vars = os::env();
|
||||
for vars.iter().advance |&(env_var, value)| {
|
||||
print(fmt!("%s=%s", env_var, value));
|
||||
print(separator);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for args.iter().advance |env_var| {
|
||||
match os::getenv(*env_var) {
|
||||
Some(var) => {
|
||||
print(var);
|
||||
print(separator);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
13
true/true.rs
Normal file
13
true/true.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
#[link(name="true", vers="1.0.0", author="Seldaek")];
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
}
|
61
yes/yes.rs
Normal file
61
yes/yes.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
#[link(name="yes", vers="1.0.0", author="Seldaek")];
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/* last synced with: yes (GNU coreutils) 8.13 */
|
||||
|
||||
extern mod extra;
|
||||
|
||||
use std::os;
|
||||
use std::io::stderr;
|
||||
use extra::getopts::*;
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
let program = copy args[0];
|
||||
let opts = ~[
|
||||
groups::optflag("h", "help", "display this help and exit"),
|
||||
groups::optflag("V", "version", "output version information and exit"),
|
||||
];
|
||||
let matches = match groups::getopts(args.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
stderr().write_line("Invalid options");
|
||||
stderr().write_line(fail_str(f));
|
||||
os::set_exit_status(1);
|
||||
return
|
||||
}
|
||||
};
|
||||
if opts_present(&matches, [~"h", ~"help"]) {
|
||||
println("yes 1.0.0");
|
||||
println("");
|
||||
println("Usage:");
|
||||
println(fmt!(" %s [STRING]... [OPTION]...", program));
|
||||
println("");
|
||||
print(groups::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts));
|
||||
return;
|
||||
}
|
||||
if opts_present(&matches, [~"V", ~"version"]) {
|
||||
println("yes 1.0.0");
|
||||
return;
|
||||
}
|
||||
let mut string = ~"y";
|
||||
if !matches.free.is_empty() {
|
||||
string = matches.free.connect(" ");
|
||||
}
|
||||
|
||||
exec(string);
|
||||
}
|
||||
|
||||
pub fn exec(string: ~str) {
|
||||
loop {
|
||||
println(string);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue