ipso icon indicating copy to clipboard operation
ipso copied to clipboard

Port of 'Ghost in the Shell - Part 6'

Open LightAndLight opened this issue 4 years ago • 0 comments

https://vermaden.wordpress.com/2021/09/13/ghost-in-the-shell-part-6-learn-shell-scripting/

An introduction to shell scripting. lsmod may be more widely available than kldstat. ipso should be able to replicate this. A sketch:

0.1

#! /usr/bin/env -S ipso --script

cmd.eachline `kldstat` \line ->
  println line

Features:

  • https://github.com/LightAndLight/ipso/issues/211
  • https://github.com/LightAndLight/ipso/issues/133
  • Block arguments

0.2

#! /usr/bin/env -S ipso --script

println "SIZE NAME"

cmd.eachline `kldstat | sed 1d` \line ->
  comp
    let [id, refs, address, size, name, ..rest] = string.split ' ' line
    println "$size $name"

Features:

  • https://github.com/LightAndLight/ipso/issues/82
  • let binding patterns
  • Piping in command literals

0.3

#! /usr/bin/env -S ipso --script

println "${ string.padleft 8 "SIZE" } NAME"

cmd.eachline `kldstat | sed 1d` \line ->
  comp
    let [id, refs, address, size, name, ..rest] = string.split ' ' line
    println "${ string.padleft 8 size } $name"

0.4

int.parseHex : String -> (| None : (), Some : Int |)
int.parseHex! : String -> Int
#! /usr/bin/env -S ipso --script

let format size name = "${ string.padleft 8 size } $name"

println (format "SIZE" "NAME")

cmd.eachline `kldstat | sed 1d` \line ->
  comp
    let [id, refs, address, size, name, ..rest] = string.split ' ' line
    println (format (toString <| int.parseHex! size) name)

Features:

  • https://github.com/LightAndLight/ipso/issues/286

0.5

#! /usr/bin/env -S ipso --script

let format size name = "${ string.padleft 8 size } $name"

println (format "SIZE" "NAME")

cmd.eachline `kldstat | sed 1d` \line ->
  comp
    let [id, refs, address, size, name, ..rest] = string.split ' ' line
    let sizeMB = int.parseHex! size / 1000000
    println (format (toString sizeMB) name)

LightAndLight avatar Sep 13 '21 12:09 LightAndLight