Giter Site home page Giter Site logo

Comments (11)

dch82 avatar dch82 commented on May 21, 2024 1

@amtoine @fdncred I implemented your oneliners into nutils!
BTW, if you have any ideas, just code it and submit a pr.

from nu_scripts.

fdncred avatar fdncred commented on May 21, 2024 1

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.

fdncred avatar fdncred commented on May 21, 2024

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.

dch82 avatar dch82 commented on May 21, 2024

Also... Is it possible to implement these 2 commands in pure Nu?

from nu_scripts.

fdncred avatar fdncred commented on May 21, 2024

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.

dch82 avatar dch82 commented on May 21, 2024

For unix-like systems, we could read from some special file to get results like who and df without external executables.

from nu_scripts.

fdncred avatar fdncred commented on May 21, 2024

ya, but then it's not cross-platform. we try really hard to be cross-platform at nushell.

from nu_scripts.

dch82 avatar dch82 commented on May 21, 2024

I mean df and who aren't necessarily cross-platform... (*cough* *cough* Microsoft *cough*)

from nu_scripts.

fdncred avatar fdncred commented on May 21, 2024

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.

amtoine avatar amtoine commented on May 21, 2024

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.

dch82 avatar dch82 commented on May 21, 2024

Does anybody have ideas for new commands?

from nu_scripts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.