dyslectric.dev
  • Communities
  • Multi-communities
  • Support Lemmy
  • Search
  • Login
  • Sign Up
Free and Open Source Software@beehaw.orgbylilith267@lemmy.blahaj.zone
1 day

I wrote a simple greeting script for fish as a fetch/motd alternative

lemmy.blahaj.zone English

Repo: codeberg.org/Lunar267/fish_cute-greeting

A very tiny bit of code but I figured some other ricing enthusiast might like use it

5
    You must log in or register to comment.

    • thingsiplay@lemmy.ml
      21 hours

      That’s really cute. I personally won’t use it (don’t even use Fish), but wanted to give some tips. First, the code is intended to run each time a new terminal (more accurately a new instance of Fish is run) is opened up, right? If so, then I suggest to optimize a bit for performance, so opening a terminal stays snappy.

      There are parts that do not change usually, so running and grabbing the content each time is a bit of waste. I’ll suggest creating a single cache file with all the content that stays the same. In example following lines

      awk -F'"' '/PRETTY_NAME/ {print $2}' /etc/os-release
      awk '/cpu cores/{c=1} c{ print $4; if (/cpu cores/) exit }' /proc/cpuinfo
      

      need to run only once, if the cache file doesn’t exist already. At start of script check if the cache file exists, and read the file once only. The file could be in /tmp/ directory, so it gets deleted with reboot and should run once and always up to date. There is also a file cat /proc/loadavg, which you could use instead using uptime | awk. So instead you could just have a more simple sed or grep command. Instead:

      uptime | awk '{ print substr($(NF-2), 1, length($(NF-2)) - 1)"% Load" }'
      

      do

      grep -o '^[^ ]*' /proc/loadavg
      

      Note my code examples are in Bash syntax, not sure if there are differences that matters here. I see you like awk a lot BTW.

      Edit: Changed the line with uptime | awk from your code, as I copy pasted the wrong line by accident before.

        • lilith267@lemmy.blahaj.zoneEnglish
          17 hours

          Thanks a lot for the advice!

          Grabbing the content each time is a bit of a waste

          In practice fish is extremely more efficient then bash with the script profiling at 9ms. Not amazing but since this will only run once when opening the shell its small enough to not be noticeable

          There is also a file cat /proc/loadavg

          So thats where it was! My original script tried to loop over all the cpu max and mins and calculate the percentage before deciding uptime was just more practical. Thanks for the info!

          I see you like awk a lot BTW

          Its just so damn easy to grab the piece of info you want with lol

          Really thanks for all the feedback Ill have to work some of your advice in when I get back to my computer

        • heliotrope@slrpnk.netEnglish
          1 day

          I love this! Gonna have to port it to ksh, but I’m definitely using this!

          • inari@piefed.zipEnglish
            23 hours

            Cute

            • Vivian@lemmy.blahaj.zone
              22 hours

              😮😮😮 neeeeeed

              thank you so much for posting, I’m obsessed

              Free and Open Source Software@beehaw.org

              foss@beehaw.org

              Subscribe from remote instance

              Create post

              Report community

              Modlog
              You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

              If it’s free and open source and it’s also software, it can be discussed here. Subcommunity of Technology.


              This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

              Visibility: Public

              This community is visible to everyone.

              95 users / Day227 users / Week292 users / Month294 users / 6 months25 posts104 comments1 local subscriber23K subscribers
              Mods: Gaywallet (they/it)@beehaw.org
              • BE: 1.0.0-beta.2
              • Modlog
              • Instances
              • Docs
              • Code
              • join-lemmy.org