Code Monkey home page Code Monkey logo

Comments (13)

foxsouns avatar foxsouns commented on September 27, 2024

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"
}
}

from cpm.

foxsouns avatar foxsouns commented on September 27, 2024

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

from cpm.

willeccles avatar willeccles commented on September 27, 2024

What is the high level goal here?

from cpm.

willeccles avatar willeccles commented on September 27, 2024

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?

from cpm.

willeccles avatar willeccles commented on September 27, 2024

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

from cpm.

eepykate avatar eepykate commented on September 27, 2024

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.

from cpm.

willeccles avatar willeccles commented on September 27, 2024

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.

from cpm.

eepykate avatar eepykate commented on September 27, 2024

from cpm.

willeccles avatar willeccles commented on September 27, 2024

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.

from cpm.

willeccles avatar willeccles commented on September 27, 2024

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.

from cpm.

foxsouns avatar foxsouns commented on September 27, 2024

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?"

from cpm.

foxsouns avatar foxsouns commented on September 27, 2024

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

from cpm.

foxsouns avatar foxsouns commented on September 27, 2024

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

from cpm.

Related Issues (16)

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.