88 lines
1.7 KiB
Bash
88 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
name="ysess-manager"
|
|
version=0.1.0
|
|
author="Joe <joe@thisisjoes.site>"
|
|
license="GNU GPLv3"
|
|
|
|
Configure() {
|
|
declare -Ag config
|
|
config=(
|
|
[extension]="ysess"
|
|
[name]="last"
|
|
[format]="+%d%m%Y_%H%M%S"
|
|
[action]="increment"
|
|
[path]="$HOME/.ysm"
|
|
)
|
|
CreateFiles
|
|
while read line
|
|
do
|
|
if echo $line | grep -F = &>/dev/null
|
|
then
|
|
varname=$(echo "$line" | cut -d '=' -f 1)
|
|
config[$varname]=$(echo "$line" | cut -d '=' -f 2-)
|
|
fi
|
|
done < ${config[path]}/ysm.conf
|
|
}
|
|
|
|
CreateFiles() {
|
|
if [ ! -d ${config[path]} ]; then
|
|
mkdir ${config[path]}
|
|
touch ${config[path]}/.last
|
|
touch ${config[path]}/ysm.conf
|
|
fi
|
|
}
|
|
|
|
CreateArray() {
|
|
sessions=(${config[path]}/*.${config[extension]})
|
|
}
|
|
|
|
UserInput() {
|
|
read -r -p "$(echo -e '\e[4mL\e[0moad/\e[4mS\e[0mave: ')" task
|
|
}
|
|
|
|
CallTask() {
|
|
case "$task" in
|
|
[Ll] ) LoadSession;;
|
|
[Ss] ) SaveSession;;
|
|
* ) InvalidInput;;
|
|
esac
|
|
}
|
|
|
|
LoadSession() {
|
|
for ((i=0;i<"${#sessions[*]}";i++)); do
|
|
echo -n "[$i] "
|
|
echo "$(basename "${sessions[$i]}" .${config[extension]})"
|
|
done
|
|
read -rp "" selection
|
|
if [ -z "$selection" ]; then selection=0;fi
|
|
python2.7 ysess -i "${sessions[$selection]}"
|
|
}
|
|
|
|
SaveSession() {
|
|
read -rp "Session name (${config[name]}):" name
|
|
if [ -z "$name" ]; then name=${config[name]};fi
|
|
python2.7 ysess -o "${config[path]}/$name.${config[extension]}"
|
|
}
|
|
|
|
Debug() {
|
|
echo Debug Enabled!
|
|
echo Sessions: ${config[path]}/*.${config[extension]}
|
|
echo Total: ${#sessions[*]}
|
|
echo Extension: ${config[extension]}
|
|
echo Name: ${config[name]}
|
|
echo Format: ${config[format]}
|
|
echo Action: ${config[action]}
|
|
echo Path: ${config[path]}
|
|
}
|
|
|
|
Main() {
|
|
Configure
|
|
CreateArray
|
|
Debug
|
|
UserInput
|
|
CallTask
|
|
}
|
|
|
|
Main
|