Comments (11)
@amtoine @fdncred I implemented your oneliners into nutils!
BTW, if you have any ideas, just code it and submit a pr.
from nu_scripts.
not at the moment. let's close this for now since it's not an issue. feel free to drop by our discord and discuss nushell scripting more.
from nu_scripts.
Nice work on integrating nushell with other externals! The only thing that I'd like to see different is to not use jc
if possible. Here's are two different techniques on how to avoid it to make them more nushelly and not require people to have other externals.
Technique 1 - detect columns
❯ df -B1 |
str replace "Mounted on" "Mountpoint" |
detect columns |
rename filesystem size used avail used% mountpoint |
into filesize size used avail |
upsert used% {|r| 100 * (1 - $r.avail / $r.size)}
╭───┬────────────────┬──────────┬──────────┬──────────┬───────┬────────────────────────────╮
│ # │ filesystem │ size │ used │ avail │ used% │ mountpoint │
├───┼────────────────┼──────────┼──────────┼──────────┼───────┼────────────────────────────┤
│ 0 │ /dev/disk3s1s1 │ 994.7 GB │ 455.1 GB │ 539.6 GB │ 45.75 │ / │
│ 1 │ /dev/disk3s6 │ 994.7 GB │ 455.1 GB │ 539.6 GB │ 45.75 │ /System/Volumes/VM │
│ 2 │ /dev/disk3s2 │ 994.7 GB │ 455.1 GB │ 539.6 GB │ 45.75 │ /System/Volumes/Preboot │
│ 3 │ /dev/disk3s4 │ 994.7 GB │ 455.1 GB │ 539.6 GB │ 45.75 │ /System/Volumes/Update │
│ 4 │ /dev/disk1s2 │ 524.3 MB │ 20.5 MB │ 503.7 MB │ 3.92 │ /System/Volumes/xarts │
│ 5 │ /dev/disk1s1 │ 524.3 MB │ 20.5 MB │ 503.7 MB │ 3.92 │ /System/Volumes/iSCPreboot │
│ 6 │ /dev/disk1s3 │ 524.3 MB │ 20.5 MB │ 503.7 MB │ 3.92 │ /System/Volumes/Hardware │
├───┼────────────────┼──────────┼──────────┼──────────┼───────┼────────────────────────────┤
│ # │ filesystem │ size │ used │ avail │ used% │ mountpoint │
╰───┴────────────────┴──────────┴──────────┴──────────┴───────┴────────────────────────────╯
Technique 2 - parse
❯ who -u | parse '{user} {tty} {datetime} {idle} {pid}' | update datetime {|r| $r.datetime | into datetime}
╭───┬─────────┬─────────┬────────────┬──────┬─────╮
│ # │ user │ tty │ datetime │ idle │ pid │
├───┼─────────┼─────────┼────────────┼──────┼─────┤
│ 0 │ fdncred │ console │ a week ago │ old │ 170 │
│ │ │ │ │ │ │
╰───┴─────────┴─────────┴────────────┴──────┴─────╯
from nu_scripts.
Also... Is it possible to implement these 2 commands in pure Nu?
from nu_scripts.
nushell doesn't have df
atm, although we've toyed with adding it before. we may still. we don't have anything that works like who
in nushell, that i know of. with lsr
we can do du -a | table -e
which approximates your tree output.
from nu_scripts.
For unix-like systems, we could read from some special file to get results like who
and df
without external executables.
from nu_scripts.
ya, but then it's not cross-platform. we try really hard to be cross-platform at nushell.
from nu_scripts.
I mean df
and who
aren't necessarily cross-platform... (*cough* *cough* Microsoft *cough*)
from nu_scripts.
I think coreutils has a df
and who
that may be cross-platform. I haven't tried them on Windows yet though.
from nu_scripts.
agree with @fdncred, i think your df
and who
can be written without external dependencies such as jc
😋
i have almost the same df
as the one above, from my scripts
def df [] {
^df -h
| str replace "Mounted on" "Mountpoint"
| detect columns
| rename filesystem size used avail used% mountpoint
| into filesize size used avail
| upsert used% {|it| 100 * (1 - $it.avail / $it.size)}
}
and for who
, the command above returns an empty list to me 🤔
so i wrote the following
def who [] {
^who -u | str replace ' \s+' ',' --all | str trim | split column "," user tty datetime pid
}
which gives me
╭───┬─────────┬──────┬────────────────────────┬──────────╮
│ # │ user │ tty │ datetime │ pid │
├───┼─────────┼──────┼────────────────────────┼──────────┤
│ 0 │ amtoine │ tty1 │ 2023-07-23 10:01 00:19 │ 592 (:0) │
╰───┴─────────┴──────┴────────────────────────┴──────────╯
and with the fix in nushell/nushell#9775, you can even do
def who [] { ^who --all --heading --users | detect columns | rename name tty date idle pid comment exit | into datetime date }which gives
╭───┬─────────┬────────┬──────────────┬───────┬─────┬─────────┬──────╮ │ # │ name │ tty │ date │ idle │ pid │ comment │ exit │ ├───┼─────────┼────────┼──────────────┼───────┼─────┼─────────┼──────┤ │ 0 │ │ system │ 16 hours ago │ │ │ │ │ │ 1 │ amtoine │ │ 16 hours ago │ 00:45 │ 0 │ │ │ │ 2 │ amtoine │ tty1 │ 16 hours ago │ 00:46 │ 627 │ (:0) │ │ ╰───┴─────────┴────────┴──────────────┴───────┴─────┴─────────┴──────╯
from nu_scripts.
Does anybody have ideas for new commands?
from nu_scripts.
Related Issues (20)
- micromamba support
- `use` of `parse-help` throws `nu::parser::expected_keyword` HOT 1
- Performance issues on man completions HOT 5
- How about nushell-completions? HOT 5
- Job.nu script no longer works HOT 2
- nu_conda list should show which environments are activated HOT 1
- Nuscript's for Pacman
- Module `rbenv` can't export command named same as module. HOT 3
- Add a basic level of CI for this repo HOT 3
- winget-completions.nu with problems? HOT 4
- Conda documentation HOT 3
- Admin commands Question HOT 1
- Fix: nushell at 0.88.0 `start` and `end` are deprecated HOT 1
- tokyo-night theme uses tokyo-storm palette HOT 7
- [new script] is dark_mode mac HOT 1
- The direnv hooks are very confusing HOT 1
- `main` branch CI is not working as expected HOT 1
- git branch cleanup returns errors. HOT 4
- PR 816 Broke Anaconda Activation Support on Windows
- 'winget show' errors on specific packages
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nu_scripts.