sustrik / uxy Goto Github PK
View Code? Open in Web Editor NEWUXY: Adding structure to the UNIX tools
License: MIT License
UXY: Adding structure to the UNIX tools
License: MIT License
This tool is awesome! Are you thinking of adding package management support so I can get the latest updates?
@sustrik when you consider uxy stable, publishing a release to pypi should be as easy as
poetry publish
On my system (Ubuntu 18.04), the ps
command prints leading spaces for some PIDs because the PID field is right-justified.
$ ps
PID TTY TIME CMD
7269 pts/7 00:00:01 bash
12455 pts/7 00:00:00 ps
$ uxy ps
PID TTY TIME CMD
7269 pts/7 "00:00:01 bash"
12459 pts/7 00:00:00 uxy
12460 pts/7 00:00:00 ps
$ uxy ps | uxy align
PID TTY TIME CMD
7269 pts/7 "00:00:01 bash"
12509 pts/7 00:00:00 uxy
12510 pts/7 00:00:00 uxy
12511 pts/7 00:00:00 ps
$
I'm in an environment where groups with spaces are common. The regular expression that extracts the output of ls
cannot handle this properly. Since there are no delimiters for user and group names, it would not be possible to get the correct user and group.
For example, this is the output with spaces in the user and group names: (users: howlem and "test user ignore" and groups: "domain users")
TYPE PERMISSIONS LINKS OWNER GROUP SIZE TIME NAME
d rwxr-xr-x 4 howlem domain users "4096 2019-05-23 14:17:07.493736735" "-0400 debian"
- rw-r--r-- 1 howlem domain users "12837 2019-05-23 11:49:51.750633915" "-0400 README.md"
- rw-r--r-- 1 test user ignore "domain users 0" "2019-05-23 15:28:01.361719083 -0400 test"
- rw-r--r-- 1 howlem domain users "0 2019-05-23 15:49:04.809507672" "-0400 test2"
- rw-r--r-- 1 howlem domain users "853 2019-05-24 10:43:18.835875117" "-0400 test.py"
- rwxr-xr-x 1 howlem domain users "21838 2019-05-28 10:24:17.890430740" "-0400 uxy"
I wrote a quick implementation of ls
. It does lose the extra ls arguments and the date/time format isn't the same.
import datetime
import os
import pwd
import grp
def uxy_cmd_ls(args, uargs):
uargs = uargs[0] if uargs else "."
content = os.listdir(uargs)
fmt = Format("TYPE PERMISSIONS LINKS OWNER GROUP SIZE TIME NAME")
writeout(fmt.render())
for entry in content:
fields = []
fstats = os.stat(os.path.join(uargs, entry))
mode = stat.filemode(fstats.st_mode)
fields.append(mode[0])
fields.append(mode[1:])
fields.append(str(fstats.st_nlink))
uid, gid = (fstats.st_uid, fstats.st_gid)
try:
user = pwd.getpwuid(uid).pw_name
except KeyError:
user = str(uid)
fields.append(encode_field(user))
try:
group = grp.getgrgid(gid).gr_name
except KeyError:
group = str(gid)
fields.append(encode_field(group))
fields.append(str(fstats.st_size))
fields.append(encode_field(datetime.datetime.fromtimestamp(fstats.st_mtime).isoformat()))
fields.append(encode_field(entry))
writeout(fmt.render(fields))
`
This was requested in #3. Moving it to a separate issue as it is independent from making uxy installable.
This project has incredible potential but having some setup issues. i tried cloning the repo and putting uxy
on my PATH
(Mac OS) but seeing some issues:
$ uxy ls
TYPE PERMISSIONS LINKS OWNER GROUP SIZE TIME NAME
ls: illegal option -- N
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
$ uxy ps
PID TTY TIME CMD
ps: illegal option -- -
usage: ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid...]]
[-g grp[,grp...]] [-u [uid,uid...]]
[-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
ps [-L]
There's a good guide here: https://github.com/kennethreitz/setup.py
I can't currently use this on Mac (unless I modify my local copy) because I don't have a python3
executable in /usr/bin
and Mac doesn't allow symlinks in that directory. I believe installing with setup.py would fix that.
If uxy ls
encounters a file with a space in its name, it ignores the portion of the file name after the space.
I haven't checked other funny characters (for example, it's legal to have a newline in a filename).
On my system, Ubuntu 18.04:
$ ls -l
total 28
-rw-r--r-- 1 kst kst 8585 May 20 11:18 README.md
-rwxr-xr-x 1 kst kst 13522 May 20 11:18 uxy
$ uxy ls
TYPE PERMISSIONS LINKS OWNER GROUP SIZE TIME NAME
- rw-r--r-- 1 kst kst 8585 "2019-05-20 11:18:33.459647439 -0700" README.md
- rwxr-xr-x 1 kst kst 13522 "2019-05-20 11:18:33.459647439 -0700" uxy
$ touch 'foo bar'
$ uxy ls
TYPE PERMISSIONS LINKS OWNER GROUP SIZE TIME NAME
- rw-r--r-- 1 kst kst 8585 "2019-05-20 11:18:33.459647439 -0700" README.md
- rw-r--r-- 1 kst kst 0 "2019-05-20 11:24:36.350283775 -0700" foo
- rwxr-xr-x 1 kst kst 13522 "2019-05-20 11:18:33.459647439 -0700" uxy
$
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.