Skip to content

Commit

Permalink
Update database.am: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-hc authored Sep 1, 2024
1 parent a67a9da commit 9b2aaca
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions modules/database.am
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ _files_header() {
else
APPSMESSAGE="YOU HAVE INSTALLED $APPSNUMB PROGRAMS"
fi
if grep -q 'usr/local/lib' $APPSPATH/*/remove 2> /dev/null; then
if grep -q 'usr/local/lib' "$APPSPATH"/*/remove 2> /dev/null; then
LIBNUMB=$(grep -l "usr/local/lib" "$APPSPATH"/*/remove | wc -l)
if [ "$LIBNUMB" = 1 ]; then
LIBSMESSAGE="AND $LIBNUMB LIBRARY"
else
LIBSMESSAGE="AND $LIBNUMB LIBRARIES"
fi
echo "- $APPSMESSAGE $LIBSMESSAGE MANAGED BY $(echo "\"$AMCLI\"" | tr a-z A-Z)"
echo "- $APPSMESSAGE $LIBSMESSAGE MANAGED BY $AMCLIUPPER"
else
echo "- $APPSMESSAGE MANAGED BY $(echo "\"$AMCLI\"" | tr a-z A-Z)"
echo "- $APPSMESSAGE MANAGED BY $AMCLIUPPER"
fi
echo ""
}

_files_sizes() {
if grep -q "usr/local/lib" ./$arg/remove; then
LIBNAME=$(cat $APPSPATH/$arg/remove | tr ' ' '\n' | grep "usr/local/lib" | head -1)
SIZE=$(du -sh $LIBNAME | cut -f1 | sort -rh | head -1)
if grep -q "usr/local/lib" ./"$arg"/remove; then
LIBNAME=$(<"$APPSPATH"/"$arg"/remove tr ' ' '\n' | grep "usr/local/lib" | head -1)
SIZE=$(du -sh "$LIBNAME" | cut -f1 | sort -rh | head -1)
else
SIZE=$(du -sh -- $arg | cut -f1 -d" ")
SIZE=$(du -sh -- "$arg" | cut -f1 -d" ")
fi
SIZE=$(echo "$SIZE" | sed 's/.$/ &/; s/$/iB/')
echo "$arg | $SIZE" >> "$AMCACHEDIR"/files-sizes
Expand Down Expand Up @@ -146,7 +146,7 @@ _files_if_appimage() {
}

_files_type() {
APPVERSION=$(cat "$AMCACHEDIR"/version-args | grep -w "$arg |" | sed 's:.*| ::')
APPVERSION=$(<"$AMCACHEDIR"/version-args grep -w "$arg |" | sed 's:.*| ::')
string=$(strings -d ./"$arg/$arg" 2>/dev/null)
FILE=$(command -v "$arg" 2>/dev/null)
LINK=$(readlink "$FILE" 2>/dev/null)
Expand All @@ -164,21 +164,21 @@ _files_type() {
}

_files_files() {
cd $APPSPATH &&
cd "$APPSPATH" || exit 1
INSTALLED_APPS=$(find -name 'remove' -printf "%h\n" 2>/dev/null | du -sh -- * 2> /dev/null | sort -rh | sed 's@.* @@')
if ! test -f "$AMCACHEDIR"/version-args; then
_check_version
fi
if ! test -f "$AMCACHEDIR"/files-type; then
for arg in $INSTALLED_APPS; do
if test -f ./$arg/remove 2>/dev/null; then
if test -f ./"$arg"/remove 2>/dev/null; then
_files_type
fi
done
fi
rm -f "$AMCACHEDIR"/files-sizes
for arg in $INSTALLED_APPS; do
if test -f ./$arg/remove 2>/dev/null; then
if test -f ./"$arg"/remove 2>/dev/null; then
_files_sizes
fi
done
Expand All @@ -189,7 +189,7 @@ _files() {
rm -f "$AMCACHEDIR"/files-args
INSTALLED_APPS=$(find -name 'remove' -printf "%h\n" 2>/dev/null | du -sh -- * 2>/dev/null | sort -rh | sed 's@.* @@')
for arg in $INSTALLED_APPS; do
if test -f ./$arg/remove 2>/dev/null; then
if test -f ./"$arg"/remove 2>/dev/null; then
APPVERSION=$(grep -w "$arg |" "$AMCACHEDIR"/version-args | tr ' ' '\n' | tail -1)
APPTYPE=$(grep -w "$arg |" "$AMCACHEDIR"/files-type | tr ' ' '\n' | tail -1)
APPSYZE=$(grep -w "$arg |" "$AMCACHEDIR"/files-sizes | tr ' ' '\n' | tail -1)
Expand Down Expand Up @@ -223,8 +223,8 @@ _files_sort_by_name() {
_files_header
rm -f "$AMCACHEDIR"/files-args-byname
_files
printf '%s\n' "- APPNAME | VERSION | TYPE | SIZE " >> "$AMCACHEDIR"/files-args-byname
printf '%s\n' "- ------- | ------- | ---- | ----" >> "$AMCACHEDIR"/files-args-byname
echo "- APPNAME | VERSION | TYPE | SIZE " > "$AMCACHEDIR"/files-args-byname
echo "- ------- | ------- | ---- | ----" >> "$AMCACHEDIR"/files-args-byname
sort "$AMCACHEDIR"/files-args 2>/dev/null >> "$AMCACHEDIR"/files-args-byname
column -t "$AMCACHEDIR"/files-args-byname
_files_total_size
Expand All @@ -235,8 +235,8 @@ _files_sort_by_size() {
_files_header
rm -f "$AMCACHEDIR"/files-args-bysize
_files
printf '%s\n' "- APPNAME | VERSION | TYPE | SIZE " >> "$AMCACHEDIR"/files-args-bysize
printf '%s\n' "- ------- | ------- | ---- | ----" >> "$AMCACHEDIR"/files-args-bysize
echo "- APPNAME | VERSION | TYPE | SIZE " > "$AMCACHEDIR"/files-args-bysize
echo "- ------- | ------- | ---- | ----" >> "$AMCACHEDIR"/files-args-bysize
cat "$AMCACHEDIR"/files-args >> "$AMCACHEDIR"/files-args-bysize 2>/dev/null
column -t "$AMCACHEDIR"/files-args-bysize
_files_total_size
Expand Down Expand Up @@ -361,11 +361,11 @@ case "$1" in
wget -q --tries=10 --timeout=20 --spider https://github.com && _completion_lists
if [ "$2" = --pkg ]; then
ARGS="$(echo "$@" | cut -f3- -d ' ' | tr -s ' ' '|')"
printf "\n Search results for packages: $ARGS\n\n" | tr '[:lower:]' '[:upper:]'
printf "\n Search results for packages: %s\n\n" "$ARGS" | tr '[:lower:]' '[:upper:]'
grep -iE "$ARGS" "$AMDATADIR/$arch-apps" --color=always | _pretty_list_compat
elif [ "$2" = --appimages ]; then
ARGS="$(echo "$@" | cut -f3- -d ' ')"
printf "\n Search results for \"$ARGS\":\n\n" | tr '[:lower:]' '[:upper:]'
printf "\n Search results for \"%s\":\n\n" "$ARGS" | tr '[:lower:]' '[:upper:]'
PATTERN="$(echo "$ARGS" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
if ! test -f "$AMCACHEDIR/$arch-appimages"; then
_online_check
Expand All @@ -374,7 +374,7 @@ case "$1" in
grep -Pi "$PATTERN" "$AMCACHEDIR/$arch-appimages" | _pretty_list_compat
else
ARGS="$(echo "$@" | cut -f2- -d ' ')"
printf "\n Search results for \"$ARGS\":\n\n" | tr '[:lower:]' '[:upper:]'
printf "\n Search results for \"%s\":\n\n" "$ARGS" | tr '[:lower:]' '[:upper:]'
PATTERN="$(echo "$ARGS" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
grep -Pi "$PATTERN" "$AMDATADIR/$arch-apps" | _pretty_list_compat
fi
Expand Down

0 comments on commit 9b2aaca

Please sign in to comment.