Readit News logoReadit News
junkblocker commented on Scripts I wrote that I use all the time   evanhahn.com/scripts-i-wr... · Posted by u/speckx
alberand · 2 months ago
My fav script to unpack anything, found a few years ago somewhere

      # ex - archive extractor
      # usage: ex <file>
      function ex() {
          if [ -f $1 ] ; then
          case $1 in
              *.tar.bz2) tar xjf $1 ;;
              *.tar.gz) tar xzf $1 ;;
              *.tar.xz) tar xf $1 ;;
              *.bz2) bunzip2 $1 ;;
              *.rar) unrar x $1 ;;
              *.gz) gunzip $1 ;;
              *.tar) tar xf $1 ;;
              *.tbz2) tar xjf $1 ;;
              *.tgz) tar xzf $1 ;;
              *.zip) unzip $1 ;;
              *.Z) uncompress $1;;
              *.7z) 7z x $1 ;;
              *) echo "'$1' cannot be extracted via ex()" ;;
          esac
          else
              echo "'$1' is not a valid file"
          fi
      }

junkblocker · 2 months ago
I had found a zsh version somewhere which I've updated a few times over the years though I don't get a chance to use it much. :'D

    un () {
 unsetopt extendedglob
 local old_dirs current_dirs lower do_cd
 if [ -z "$1" ]
 then
  print "Must supply an archive argument."
  return 1
 fi
 if [ -d "$1" ]
 then
  print "Can't do much with directory arguments."
  return 1
 fi
 if [ ! -e "$1" -a ! -h "$1" ]
 then
  print "$1 does not exist."
  return 1
 fi
 if [ ! -r "$1" ]
 then
  print "$1 is not readable."
  return 1
 fi
 do_cd=1 
 lower="${(L)1}" 
 old_dirs=(*(N/)) 
 undone=false 
 if which unar > /dev/null 2>&1 && unar "$1"
 then
  undone=true 
 fi
 if ! $undone
 then
  INFO="$(file "$1")" 
  INFO="${INFO##*: }" 
  if command grep -a --line-buffered --color=auto -E "Zstandard compressed data" > /dev/null <<< "$INFO"
  then
   zstd -T0 -d "$1"
  elif command grep -a --line-buffered --color=auto -E "bzip2 compressed" > /dev/null <<< "$INFO"
  then
   bunzip2 -kv "$1"
  elif command grep -a --line-buffered --color=auto -E "Zip archive" > /dev/null <<< "$INFO"
  then
   unzip "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "RAR archive" > /dev/null
  then
   unrar e "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E 'xar archive' > /dev/null
  then
   xar -xvf "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "tar archive" > /dev/null
  then
   if which gtar > /dev/null 2>&1
   then
    gtar xvf "$1"
   else
    tar xvf "$1"
   fi
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "LHa" > /dev/null
  then
   lha e "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "LHa" > /dev/null
  then
   lha e "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "compress'd" > /dev/null
  then
   uncompress -c "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "xz compressed" > /dev/null
  then
   unxz -k "$1"
   do_cd=0 
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "7-zip" > /dev/null
  then
   7z x "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "RPM " > /dev/null
  then
   if [ "$osname" = "Darwin" ]
   then
    rpm2cpio "$1" | cpio -i -d --quiet
   else
    rpm2cpio "$1" | cpio -i --no-absolute-filenames -d --quiet
   fi
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "cpio archive" > /dev/null
  then
   cpio -i --no-absolute-filenames -d --quiet < "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E "Debian .* package" > /dev/null
  then
   dpkg-deb -x "$1" .
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i " ar archive" > /dev/null
  then
   ar x "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "ACE archive" > /dev/null
  then
   unace e "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "ARJ archive" > /dev/null
  then
   arj e "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "xar archive" > /dev/null
  then
   xar -xvf "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "ZOO archive" > /dev/null
  then
   zoo x "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -Ei "(tnef|Transport Neutral Encapsulation Format)" > /dev/null
  then
   tnef "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "InstallShield CAB" > /dev/null
  then
   unshield x "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -Ei "(mail|news)" > /dev/null
  then
   formail -s munpack < "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "uuencode" > /dev/null
  then
   uudecode "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "cab" > /dev/null
  then
   cabextract "$1"
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E -i "PPMD archive" > /dev/null
  then
   ln -s "$1" . && ppmd d "$1" && rm `basename "$1"`
  elif [[ $lower == *.zst ]]
  then
   zstd -T0 -d "$1"
  elif [[ $lower == *.bz2 ]]
  then
   bunzip2 -kv "$1"
  elif [[ $lower == *.zip ]]
  then
   unzip "$1"
  elif [[ $lower == *.jar ]]
  then
   unzip "$1"
  elif [[ $lower == *.xpi ]]
  then
   unzip "$1"
  elif [[ $lower == *.rar ]]
  then
   unrar e "$1"
  elif [[ $lower == *.xar ]]
  then
   xar -xvf "$1"
  elif [[ $lower == *.pkg ]]
  then
   xar -xvf "$1"
  elif [[ $lower == *.tar ]]
  then
   if which gtar > /dev/null 2>&1
   then
    gtar xvf "$1"
   else
    tar xvf "$1"
   fi
  elif [[ $lower == *.tar.zst || $lower == *.tzst ]]
  then
   which gtar > /dev/null 2>&1
   if [[ $? == 0 ]]
   then
    gtar -xv -I 'zstd -T0 -v' -f "$1"
   elif [[ ${OSTYPE:l} == linux* ]]
   then
    tar -xv -I 'zstd -T0 -v' -f "$1"
   else
    zstd -d -v -T0 -c "$1" | tar xvf -
   fi
  elif [[ $lower == *.tar.gz || $lower == *.tgz ]]
  then
   which gtar > /dev/null 2>&1
   if [[ $? == 0 ]]
   then
    gtar zxfv "$1"
   elif [[ ${OSTYPE:l} == linux* ]]
   then
    tar zxfv "$1"
   else
    gunzip -c "$1" | tar xvf -
   fi
  elif [[ $lower == *.tar.z ]]
  then
   uncompress -c "$1" | tar xvf -
  elif [[ $lower == *.tar.xz || $lower == *.txz ]]
  then
   which gtar > /dev/null 2>&1
   if [[ $? == 0 ]]
   then
    xzcat "$1" | gtar xvf -
   else
    xzcat "$1" | tar xvf -
   fi
  elif echo "$INFO" | command grep -a --line-buffered --color=auto -E 'gzip compressed' > /dev/null || [[ $lower == *.gz ]]
  then
   if [[ $lower == *.gz ]]
   then
    gzcat -d "$1" > "${1%.gz}"
   else
    cat "$1" | gunzip -
   fi
   do_cd=0 
  elif [[ $lower == *.tar.bz2 || $lower == *.tbz ]]
  then
   bunzip2 -kc "$1" | tar xfv -
  elif [[ $lower == *.tar.lz4 ]]
  then
   local mytar
   if [[ -n "$(command -v gtar)" ]]
   then
    mytar=gtar 
   else
    mytar=tar 
   fi
   if [[ -n "$(command -v lz4)" ]]
   then
    $mytar -xv -I lz4 -f "$1"
   elif [[ -n "$(command -v lz4cat)" ]]
   then
    lz4cat -kd "$1" | $mytar xfv -
   else
    print "Unknown archive type: $1"
    return 1
   fi
  elif [[ $lower == *.lz4 ]]
  then
   lz4 -d "$1"
  elif [[ $lower == *.epub ]]
  then
   unzip "$1"
  elif [[ $lower == *.lha ]]
  then
   lha e "$1"
  elif which aunpack > /dev/null 2>&1
  then
   aunpack "$@"
   return $?
  else
   print "Unknown archive type: $1"
   return 1
  fi
 fi
 if [[ $do_cd == 1 ]]
 then
  current_dirs=(*(N/)) 
  for i in {1..${#current_dirs}}
  do
   if [[ $current_dirs[$i] != "$old_dirs[$i]" ]]
   then
    cd "$current_dirs[$i]"
    ls
    break
   fi
  done
 fi
    }

junkblocker commented on Introduction to GrapheneOS   dataswamp.org/~solene/202... · Posted by u/renehsz
junkblocker · 3 months ago
There did not seem to be an RCS story. Whether the device is RCS capable or not seems to be up to some unfathomable Google logic the tickling of which didn't work for me. Having old RCS chat histories and new RCS chats not work made me go back to stock quick.

Deleted Comment

junkblocker commented on Yahoo change their ToS to let them scrape your email content   legal.yahoo.com/us/en/yah... · Posted by u/junkblocker
junkblocker · 9 months ago
Quoting

    Use of AI and Third-Party AI Providers. Some of our Services have features and functionality powered by our trusted third-party AI providers (“AI Providers”). AI-powered chat service provided by Microsoft Copilot relies on search services from Bing. By utilizing our Services, you consent to sharing data that you provide to us, or that resides within your Yahoo account, including your Yahoo Mail inbox with our AI Providers for the purpose of enhancing features within our Services made available to you. In some instances, use of AI query features may be governed by the AI Provider’s terms of service and privacy policy. You understand and agree that content or responses generated by AI may contain inaccuracies and should never be relied upon without independent verification. Yahoo does not control the content or responses provided by AI Providers, and makes no representations or warranties about the accuracy or completeness of such content or responses (or the sites and sources accessed through such content or responses). You also agree not to enter sensitive personal information into any AI powered query.

junkblocker commented on Linux Text Manipulation   yusuf.fyi/posts/linux-tex... · Posted by u/zerojames
dmonitor · 2 years ago
There's a lot of better ways to do this. For starters, the sp script is bash. He could just edit the script. There's also a function for returning the metadata in machine-parseable syntax:

  function sp-metadata {
    # Prints the currently playing track in a parseable format.
  
    dbus-send                                                                   \
    --print-reply                                  `# We need the reply.`       \
    --dest=$SP_DEST                                                             \
    $SP_PATH                                                                    \
    org.freedesktop.DBus.Properties.Get                                         \
    string:"$SP_MEMB" string:'Metadata'                                         \
    | grep -Ev "^method"                           `# Ignore the first line.`   \
    | grep -Eo '("(.*)")|(\b[0-9][a-zA-Z0-9.]*\b)' `# Filter interesting fiels.`\
    | sed -E '2~2 a|'                              `# Mark odd fields.`         \
    | tr -d '\n'                                   `# Remove all newlines.`     \
    | sed -E 's/\|/\n/g'                           `# Restore newlines.`        \
    | sed -E 's/(xesam:)|(mpris:)//'               `# Remove ns prefixes.`      \
    | sed -E 's/^"//'                              `# Strip leading...`         \
    | sed -E 's/"$//'                              `# ...and trailing quotes.`  \
    | sed -E 's/"+/|/'                             `# Regard "" as seperator.`  \
    | sed -E 's/ +/ /g'                            `# Merge consecutive spaces.`
  }

But as the other replier mentioned, the point was to show off an example of how text manipulation skills can solve many problems, not solve this specific problem in the best way possible.

junkblocker · 2 years ago
TIL a neat way to add comments to continued shell lines. Thanks!
junkblocker commented on $HOME, not so sweet $HOME   gist.github.com/sharadhr/... · Posted by u/delta_p_delta_x
mid-kid · 2 years ago
I keep a small series of patches for various software on my system, to fix, or at least relocate, config files to XDG locations[1]. I do this for applications I care about keeping their state. For other applications I either set the environment variables or remove the dirs on login[2]. Of course, the complexity of the project and my familiarity with the language also affects whether I bother with it. Not gonna be able to change ~/.cargo or ~/.dotnet soon (unless someone has patches for those?)

It's buried in my gentoo config, but I wonder if there'd be a good way to make this useful on other distros.

[1]: https://github.com/search?q=repo%3Amid-kid%2Fgentoo-config%2...

[2]: https://github.com/mid-kid/config/blob/master/shell/.zprofil...

junkblocker · 2 years ago
Regarding ~/.cargo (and other tools), I've had some success with following suggestions from https://github.com/b3nj5m1n/xdg-ninja

u/junkblocker

KarmaCake day60December 5, 2012View Original