#!/bin/bash
# pipeInxi (similar to pipeNeofetch)
# call from .config/openbox/menu.xml like
#
# mk rnd tmp
tmp="/tmp/$RANDOM-$$"
trap '[ -n "$tmp" ] && rm -fr "$tmp"' EXIT
mkdir -m 700 "$tmp" || { echo '!! unable to create a tmpdir' >&2; tmp=; exit 1; }
# header
header () {
cat << HEAD
HEAD
}
# footer
footer () {
cat << FOOT
FOOT
}
xmlescape () {
echo "$@" | sed 's/&/\&/g; s/\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g; s/^[ \t]*//;s/[ \t]*$//'
}
# checks critical
command -v inxi >/dev/null 2>&1 || { header; echo " "; footer ; exit 1; }
# make some tmp files, how about all at once
inxido () {
c="0"
array=( -S -M -C -G -A -N no-D no-P -s -I ) # ignore option by adding 'no'
for i in "${array[@]}"
do
if ! [[ "$i" =~ ^no.* ]]; then
( (inxi "$i" -c 0 | tr -s ' ' & wait) > "$tmp/$c" ) &
((c=c+1))
fi
done
wait
}
inxido || exit
pretty () {
for file in "$tmp"/*
do
cut -d ' ' -f1 "$file" > "$tmp/tmp"
cut -d ' ' -f2- "$file" >> "$tmp/tmp"
mv "$tmp/tmp" "$file" || exit
done
}
pretty || exit
# count files for '' purposes
count="$(ls -1q "$tmp" | wc -l)"
# main
header
# items loop over files and over lines in those files
c="0"
for file in "$tmp"/*
do
((c=c+1))
while read -r line
do
if (( ${#line} > 2 )); then
line=$(xmlescape "$line")
line="${line//_/__}"
echo "-
bash -c \"echo '$line' | /usr/bin/xsel --clipboard\"
"
fi
done <"$file"
#echo " "
(( c < count )) && echo ""
done
footer