• cally [he/they]@pawb.social
        link
        fedilink
        English
        arrow-up
        9
        ·
        2 days ago

        perhaps i too will post code on the internet

        here is a shell script i wrote for automating filenames for markdown files (blog posts):

        code
        #!/bin/sh
        set -e
        
        datecmd="date +%Y-%m-%d"
        
        if [ -z "$1" ]; then
          printf "Post title: " >&2
          read -r title
        else
          title="$1"
        fi
        
        file="$($datecmd)_$title.md"
        
        if [ -f "$file" ]; then
          printf "Error: post '$file' already exists.\n" >&2
          exit 1
        fi
        
        ${EDITOR:-nano} "$file"
        

        im not sure why i made it since i could just look at what date it is and write it down manually in the file name, but i felt like doing that as a quick hack

        • timsjel@piefed.world
          link
          fedilink
          English
          arrow-up
          2
          ·
          22 hours ago

          Here is my most recent script, not gonna lie, pretty proud of this bad boy. /s

          shjava per/med/xwpp01 A001 conv.txt

          echo ‘yo’

          shjava per/med/xwpp01 A002 conv.txt

          echo ‘yo’

          shjava per/med/xwpp01 A003 conv.txt

          echo ‘yo’

          shjava per/med/xwpp01 A004 conv.txt

          echo ‘yo’

          shjava per/med/xwpp01 A005 conv.txt

          echo ‘yo’

          shjava per/med/xwpp01 A006 conv.txt

          echo ‘yo’

          shjava per/med/xwpp01 A007 conv.txt

          echo ‘yo’

          shjava per/med/xwpp01 A008 conv.txt

          echo ‘yo’

        • bestelbus22@lemmy.worldOP
          link
          fedilink
          arrow-up
          1
          ·
          20 hours ago

          Love this kind of stuff. I have a whole reposity of fish functions that do stuff because I’m too lazy :)

        • yetAnotherUser@discuss.tchncs.de
          link
          fedilink
          arrow-up
          1
          ·
          21 hours ago

          Only thing I can recommend (as well as for literally any script) is using set -u. Only because it’s awful to debug unset variables and there’s never a use case for using unset variables.

    • bleistift2@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      11
      ·
      edit-2
      2 days ago

      TIL. I grew up with ‘suicide is bad, filicide is ok’. I guess the times are a-changin’