i3-settree: Add saving functionality
This commit is contained in:
parent
b740748e71
commit
b0ddc8ebaf
35
i3-settree
35
i3-settree
@ -23,7 +23,7 @@ log() {
|
||||
return 0
|
||||
}
|
||||
prepare_input() {
|
||||
options=""
|
||||
options="Save"
|
||||
for file in "$treespath"/*; do
|
||||
if ! [ -r "$file" ]; then
|
||||
# Cannot read the file; skip it
|
||||
@ -33,16 +33,20 @@ prepare_input() {
|
||||
# File is not a json structure; skip it
|
||||
continue
|
||||
fi
|
||||
if [[ "$file" = "$treespath/$name-layout-"* ]]; then
|
||||
# File is an unmodified saved tree; skip it
|
||||
continue
|
||||
fi
|
||||
if [ "$(basename -s ".json" -- "$file")" = "Save" ]; then
|
||||
# File conflicts with reserved word "Save"; skip it
|
||||
continue
|
||||
fi
|
||||
if ! [ -f "$file" ]; then
|
||||
# Glob failed and no files exist; error
|
||||
return 1
|
||||
fi
|
||||
if [ -z "$options" ]; then
|
||||
options="$(basename -s ".json" -- "$file")"
|
||||
else
|
||||
options="$options
|
||||
options="$options
|
||||
$(basename -s ".json" -- "$file")"
|
||||
fi
|
||||
done
|
||||
printf "%s" \
|
||||
"$options"
|
||||
@ -52,7 +56,7 @@ $(basename -s ".json" -- "$file")"
|
||||
# Steps
|
||||
step_validate_deps() {
|
||||
# Ensure we have all the programs we need to do this
|
||||
for dep in rofi i3-msg; do
|
||||
for dep in mkdir date rofi i3-msg notify-send; do
|
||||
if ! command -v "$dep" > /dev/null 2>&1; then
|
||||
log "Could not validate dependency \"$dep\""
|
||||
return 1
|
||||
@ -90,9 +94,22 @@ step_get_input() {
|
||||
}
|
||||
step_act() {
|
||||
# Do the do
|
||||
# Using a case statement here in case I want to implement saving
|
||||
# functionality later
|
||||
case "$choice" in
|
||||
Save)
|
||||
file="$treespath/$name-layout-$(date +%s%N).json"
|
||||
if [ -f "$file" ]; then
|
||||
log "Not clobbering existing layout file: $file"
|
||||
return 60
|
||||
fi
|
||||
i3-save-tree > "$file"
|
||||
notify-send \
|
||||
-u normal \
|
||||
-a "$name" \
|
||||
-t 3000 \
|
||||
-i dialog-information \
|
||||
"Saved Layout" \
|
||||
"Saved current i3 tree to:\n$file"
|
||||
;;
|
||||
*)
|
||||
i3-msg "append_layout $choicefile" > /dev/null 2>&1
|
||||
if [ -r "$choicefile.rc" ]; then
|
||||
|
Loading…
Reference in New Issue
Block a user