willeccles / cpm

🌵 A wrapper for package managers to make them consistent for those of us who are lazy.
MIT License
69 stars 13 forks source link

missing implimentation for slack's "files" (#27) #28

Closed foxsouns closed 3 years ago

foxsouns commented 3 years ago

Slackware needs a proper implementation of files. This is being worked on in pull request #44. Assuming everything looks good, this issue should be resolved soon.

foxsouns commented 3 years ago

i'm trying to come up with a replacement for cat and tail, and i'm running into a wall. the way i would go about this including coreutils would be something like the following also i need help just making sure this works

# list all in a text file piped to lsftr after string $1
# usage: filetowrite="/dir/file"; cat $(filetowrite) | lsftr $(filetowrite) "FILES:"
lsftr() {
  i=0
  while read -r line; if [ "$2" != $(STDIN) ]; do
    i=$((i + 1))
  done
  tail +$(i) "$1"
}
}
foxsouns commented 3 years ago

if i'm overcomplicating this, and there's an easy way to do this, please tell me

willeccles commented 3 years ago

What is the high level goal here?

willeccles commented 3 years ago

Oh, I see. I think it's best to do something like this:

# come up with a more creative name for this function
filelist() {
  while IFS= read -r line; do
    [ "$line" = "FILE LIST:" ] && break
  done
  while IFS= read -r line; do
    printf "%s\n" "$line"
  done
}

@6gk thoughts?

willeccles commented 3 years ago

This can be combined into one loop with a flag variable and another conditional, which is probably clearer.

eepykate commented 3 years ago

Sage's impl hurts my brain

I guess yours seems fine, will. However I'm still really confused about what's happening, not helped by not even knowing the file format or idea.

willeccles commented 3 years ago

See #27, that's where I just went and found the file in question. I think the screenshot is showing the file/command output to be parsed.

eepykate commented 3 years ago

Ahh, I see.

Unless there there's weird things going on with whitespace (trailing, leading, multiple mid-word, etc), you shouldn't need to specify IFS=

stopslacking() {
  unset files
  while read -r line; do
    [ "$line" = "FILE LIST:" ] && files=1
    [ "$files" ] && printf "%s\n" "$line"
  done
}

Would probably work if you want to use a single loop, however due to the test it will be mildly slower so ehhh (the speed differences are literally irrelevant on anything but an intel 4004 but ehhhh)

willeccles commented 3 years ago

Something like this might work:

slacklist() {
  pkginfo="/var/whatever/$1"
  if [ -f "$pkginfo" ];
    unset found
    while IFS= read -r line; do
      [ "$line" = "FILE LIST:" ] && found=1
      [ "$found" ] && printf "%s\n" "$line"
    done <"$pkginfo"
  else
    # error handling
  fi
}

Call it as slacklist zsh, for example.

willeccles commented 3 years ago

Unless there there's weird things going on with whitespace (trailing, leading, multiple mid-word, etc), you shouldn't need to specify IFS=

I almost always do it anyway, just in case for some reason someone has set it to something else in an enclosing scope or outside the script for some reason, that sort of thing.

foxsouns commented 3 years ago

Sage's impl hurts my brain

i've been overthinking this for months now, so that's a fair opinion

for error handling it should be something of sorts like (this is in psuedo as i'm away from my cpu atm)

if [ -d /var/pkgthing ]
  if [ -f "/var/pkgthing/$1" ]
    pem "something happened"
   else pem "not in db, try updating"
  else pem "no db, are you using slackware?"
foxsouns commented 3 years ago

also, that var directory is /var/log/packages/PACKAGE

foxsouns commented 3 years ago

i've put it all together at https://github.com/foxsouns/cpm/tree/slackfiles, i guess ill pr and let reviews happen