Last active
March 10, 2019 01:25
-
-
Save nejni-marji/1729924f7fa7cf90b2be6c826811c20d to your computer and use it in GitHub Desktop.
dropdown terminal for i3?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# dropdown_terminal.sh | |
# | |
# Usage: dropdown_terminal.sh | |
# Just call it to open the terminal, call it again to close it. | |
# | |
# If you're familliar with tmux, it also sets a session group, so maybe this | |
# could be extended to utilize those in some way, but I'm probably not going | |
# to do that myself. | |
# | |
# Actually, if you want, you can take bin/tmx from my Dotfiles repo and use | |
# that instead if you really wanted to have manual access, but I'm not sure how | |
# much anyone cares about that. | |
DROPDOWN_SCRIPT="$0" | |
DROPDOWN_ARG=dropdown_initialization_argument | |
start_terminal() { | |
TERM_ID="$(i3-msg -t get_tree | jq '.. | select(.marks? | contains(["dropdown"])?) | .id')" | |
if [[ -z $TERM_ID ]]; then | |
urxvt -T dropdown -e "$DROPDOWN_SCRIPT" "$DROPDOWN_ARG" & | |
else | |
i3-msg "[con_id=$TERM_ID] kill" | |
fi | |
} | |
start_dropdown() { | |
# set_urxvt_title() { | |
# echo -ne "\033]0;$1\007" | |
# } | |
# set_urxvt_title dropdown | |
count=0 | |
while ! i3-msg '[title="^dropdown$"] mark dropdown' | jq -e '.[].success'; do | |
count=$(($count+1)) | |
if [[ $count -gt 20 ]]; then | |
echo "Attempt to mark container timed out." | |
sleep 3 | |
exit 1 | |
fi | |
echo "Could not mark container. Does it exist?" | |
sleep 0.1 | |
done | |
# Float, resize, and move the dropdown terminal. | |
i3-msg '[con_mark="^dropdown$"] floating enable, sticky enable, resize set width 100 ppt height 50 ppt, move position 0 0' | |
# Attach or create a tmux session named dropdown. | |
tmux attach-session -t dropdown >/dev/null \ | |
|| tmux new-session -t dropdown -s dropdown | |
# In new-session only, the -t flag actually sets a group, which might be | |
# useful to people familliar with tmux. It's not used at all here, but for | |
# the sake of being able to add it later without having to recreate the | |
# session, it's included anyway. | |
} | |
# Check if the script was called by itself using the magic word. | |
# Otherwise, perform as normal. | |
case $1 in | |
$DROPDOWN_ARG) | |
start_dropdown | |
;; | |
*) | |
start_terminal | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment