Commit fa440cef authored by Roman Alifanov's avatar Roman Alifanov

Initial commit

parents
#!/bin/bash
PPpMGR_RANDOM="${RANDOM}"
valid_fs=("btrfs" "ext4")
# Проверяем, установлено ли yad
if ! command -v yad &> /dev/null; then
echo "Необходимо установить yad. Запустите 'sudo apt-get install yad' для установки."
exit 1
fi
PP_default_prefixes_directory="$HOME/PortProton/prefixes"
percent_bar() {
local percentage=$(echo "$1" | sed 's/%//')
local total=$2
local filled=$(echo "($percentage*$total)/100" | bc)
local empty=$((total-filled))
printf "["
for ((i=0; i<filled; i++)); do
printf "▇"
done
for ((i=0; i<empty; i++)); do
printf "_"
done
printf "]"
}
PP_default_prefixes_directory="$HOME/PortProton/prefixes"
pfxparce() {
target_directory="$1"
for entry in $PP_default_prefixes_directory/*
do
# Проверяем, является ли элемент директорией
if [ -d "$entry" ]; then
# Получаем полный путь к директории
real_path=$(realpath "$entry")
# Проверяем, содержит ли путь указанную точку
if [[ "$real_path" =~ "$target_directory" ]]; then
# Извлекаем имя префикса и его реальный путь
prefix_name=$(basename $entry)
echo "$prefix_name|$real_path"
fi
fi
done
}
gui() {
[[ -z "$(which yad)" ]] && echo 'You need to install "yad" in your system.' && exit 1
old_IFS=$IFS && IFS=$'|'
local tab_count=0
for tab in $(df -T "$HOME" /mnt/* /run/media/$USER/* | tail -n +2 | awk '{printf "%s %s %s|", $7,$2,$6}') ; do
IFS=$' ' read -r mnt_name mnt_fstype occupancy_percent <<< "$tab"
local PPpMGR_BUTTONS=()
if [[ "${valid_fs[@]}" =~ "$mnt_fstype" ]]; then
echo "Found valid filesystem: $mnt_fstype"
else
echo "Invalid filesystem: $mnt_fstype, continuing..."
continue
fi
prefixes_in_mnt=$(pfxparce "$mnt_name")
IFS=$'\n'
for pfx in $prefixes_in_mnt ; do
((button_count++))
IFS=$'|' read -r pfx_name pfx_dir <<< "$pfx"
local PPpMGR_BUTTONS[$button_count]="--field=$pfx_name:FBTN"
done
echo "$prefixes_in_mnt"
local occupancy_percent_bar=$(percent_bar "$occupancy_percent" "25")
local PPpMGR_TAB[$tab_count]="--tab= $(echo $mnt_name | sed 's/_/ /') !drive-harddisk"
((tab_count++))
yad --plug="$PPpMGR_RANDOM" --tabnum=$tab_count --form \
--separator='|' \
--field="Занято на диске $occupancy_percent: \n\
$occupancy_percent_bar:LBL" \
\
--field="Тип файловой системы: $mnt_fstype:LBL" \
\
\
${PPpMGR_BUTTONS[@]} \
\
2>/dev/null &
done
yad --key=$PPpMGR_RANDOM --class=PortProton --notebook --borders=3 --width=200 --height=400 \
--title "PPpMGR" --tab-pos=left ${PPpMGR_TAB[@]} 2>/dev/null
YAD_STATUS="$?"
IFS=${old_IFS}
[[ "$YAD_STATUS" == "1" || "$YAD_STATUS" == "252" ]] && exit 0
}
gui
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment