i3-settree: Add saving functionality
This commit is contained in:
35
i3-settree
35
i3-settree
@@ -23,7 +23,7 @@ log() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
prepare_input() {
|
prepare_input() {
|
||||||
options=""
|
options="Save"
|
||||||
for file in "$treespath"/*; do
|
for file in "$treespath"/*; do
|
||||||
if ! [ -r "$file" ]; then
|
if ! [ -r "$file" ]; then
|
||||||
# Cannot read the file; skip it
|
# Cannot read the file; skip it
|
||||||
@@ -33,16 +33,20 @@ prepare_input() {
|
|||||||
# File is not a json structure; skip it
|
# File is not a json structure; skip it
|
||||||
continue
|
continue
|
||||||
fi
|
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
|
if ! [ -f "$file" ]; then
|
||||||
# Glob failed and no files exist; error
|
# Glob failed and no files exist; error
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ -z "$options" ]; then
|
options="$options
|
||||||
options="$(basename -s ".json" -- "$file")"
|
|
||||||
else
|
|
||||||
options="$options
|
|
||||||
$(basename -s ".json" -- "$file")"
|
$(basename -s ".json" -- "$file")"
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
printf "%s" \
|
printf "%s" \
|
||||||
"$options"
|
"$options"
|
||||||
@@ -52,7 +56,7 @@ $(basename -s ".json" -- "$file")"
|
|||||||
# Steps
|
# Steps
|
||||||
step_validate_deps() {
|
step_validate_deps() {
|
||||||
# Ensure we have all the programs we need to do this
|
# 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
|
if ! command -v "$dep" > /dev/null 2>&1; then
|
||||||
log "Could not validate dependency \"$dep\""
|
log "Could not validate dependency \"$dep\""
|
||||||
return 1
|
return 1
|
||||||
@@ -90,9 +94,22 @@ step_get_input() {
|
|||||||
}
|
}
|
||||||
step_act() {
|
step_act() {
|
||||||
# Do the do
|
# Do the do
|
||||||
# Using a case statement here in case I want to implement saving
|
|
||||||
# functionality later
|
|
||||||
case "$choice" in
|
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
|
i3-msg "append_layout $choicefile" > /dev/null 2>&1
|
||||||
if [ -r "$choicefile.rc" ]; then
|
if [ -r "$choicefile.rc" ]; then
|
||||||
|
Reference in New Issue
Block a user