adb-twrp/tools/filemanager.sh

108 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2022-04-22 23:38:10 +03:00
function get_term_size() {
# Get terminal size ('stty' is POSIX and always available).
# This can't be done reliably across all bash versions in pure bash.
read -r LINES COLUMNS < <(stty size)
# Max list items that fit in the scroll area.
((max_items=LINES-3))
return $max_items
}
#CHECK IF ZIP
function checkzip {
if [[ $1 == *.zip ]]; then
confirm_question
if [[ $? -eq 0 ]];
then
return 0
else
return 1
fi
else
echo "This is not a ZIP file."
return 1
fi
}
function checker {
if [ -f "${list_dir[$selected]}" ];
then
checkzip "${list_dir[$selected]}"
if [[ $? == 0 ]]; then
push_install "${list_dir[$selected]}"
else
filemanager
fi
elif [ -d "${list_dir[$selected]}" ];
then
cd "${list_dir[$selected]}"
clear
start_scroll=0
stop_scroll=$max_items
filemanager
fi
}
get_term_size
start_scroll=0
stop_scroll=$max_items
#FILE NAVIGATING
function filemanager {
clear
arr=(*)
local other=0
list_dir=("..")
if [[ ${#arr[@]} -gt $max_items ]]; then
local d=1
if [[ $stop_scroll -le ${#arr[@]} ]]; then
for ((i=$start_scroll; i < stop_scroll; i++)); do
list_dir[d]+=${arr[i]}
((d++))
done
if [[ $start_scroll -ne 0 ]]; then
list_dir[0]="..."
elif [[ $start_scroll -eq 0 ]]; then
list_dir[0]='..'
fi
if [[ $stop_scroll != ${#arr[@]} ]]; then
list_dir[d]="..."
fi
start_scroll=$stop_scroll
stop_scroll=$((stop_scroll+max_items))
else
stop_scroll=${#arr[@]}
other=$((stop_scroll-$max_items))
filemanager
fi
else
list_dir=(".." *)
fi
select_option "${list_dir[@]}"
selected=$?
if [[ $selected == $d ]];
then
filemanager
elif [[ $selected -eq 0 && $start_scroll -ne 0 && $start_scroll -ne $max_items ]];
then
start_scroll=$(( start_scroll-(max_items*2+other) ))
stop_scroll=$(( stop_scroll-(max_items*2+other) ))
if [[ $start_scroll -lt 0 ]]; then
start_scroll=0
stop_scroll=$max_items
fi
filemanager
else
checker
fi
}