From 31a4bc0768077bfe3f485825dafa0a91f5969b24 Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Wed, 24 Jun 2020 16:05:34 +0200 Subject: [PATCH] Use st as terminal Switch from gnome-terminal to st (see fork on github). Open new terminal by default in the same working-dir as current window. Modify scratchpad-terminal to work with every terminal. --- .config/i3/config | 13 +++++++++---- .config/i3/scratchpad-terminal.sh | 29 +++++++++++++++++------------ .config/zsh/.zshrc | 3 ++- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.config/i3/config b/.config/i3/config index 9223b85..c2b99ee 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -33,7 +33,9 @@ floating_modifier $mod # set $TERMINAL kitty # bindsym $mod+Return exec i3-sensible-terminal # bindsym $mod+Return exec kitty -bindsym $mod+Return exec gnome-terminal --hide-menubar +# bindsym $mod+Return exec gnome-terminal --hide-menubar +bindsym $mod+Return exec st -d "$(xcwd)" +bindsym $mod+Shift+Return exec st # kill focused window bindsym $mod+Shift+q kill @@ -206,19 +208,22 @@ bindsym XF86RFKill exec --no-startup-id ~/.config/i3/airplane-mode-notify.sh exec --no-startup-id compton -b # scratchpad-terminal -for_window [class="Gnome-terminal" title="^scratchpad-terminal$"] \ +for_window [class="st-256color" title="^scratchpad-terminal$"] \ move scratchpad, \ sticky enable, \ scratchpad show, \ resize set 1600 900, \ border none, \ move position center +# hide scratchpad-terminal again when restarting i3 +exec_always i3-msg '[class="St" title="^scratchpad-terminal$"] scratchpad show' # show scratchpad-terminal or create one if none exists -bindsym $mod+comma exec ~/.config/i3/scratchpad-terminal.sh -s +bindsym $mod+comma exec ~/.config/i3/scratchpad-terminal.sh -s -c st-256color -n scratchpad-terminal -e st # hide scratchpad-terminal indepedent of where the focus sits -bindsym $mod+Shift+comma exec ~/.config/i3/scratchpad-terminal.sh -h +bindsym $mod+Shift+comma exec ~/.config/i3/scratchpad-terminal.sh -h -c st-256color -n scratchpad-terminal bindsym $mod+Shift+m move scratchpad +bindsym $mod+Shift+o scratchpad show bindsym $mod+Shift+s [class="^Spotify$"] scratchpad show bindsym $mod+Shift+t [class="^TelegramDesktop$"] scratchpad show diff --git a/.config/i3/scratchpad-terminal.sh b/.config/i3/scratchpad-terminal.sh index df387c9..c028dd2 100755 --- a/.config/i3/scratchpad-terminal.sh +++ b/.config/i3/scratchpad-terminal.sh @@ -2,50 +2,55 @@ exec >/dev/null -CLASS="Gnome-terminal" -NAME="scratchpad-terminal" - -while getopts "hn:s" FLAGS; do +while getopts "c:e:hn:s" FLAGS; do case "$FLAGS" in + c) W_CLASS="$OPTARG";; + e) COMMAND="$OPTARG";; h) HIDE=1;; - n) NAME="$OPTARG";; + n) W_NAME="$OPTARG";; s) SHOW=1;; *) exit 1;; esac done shift $(($OPTIND - 1 )) +[ -n "$W_CLASS" ] || return 1 +[ -n "$W_NAME" ] || return 1 +[ -z "$SHOW" ] || [ -n "$COMMAND" ] || return 1 + TREE="$(i3-msg -t get_tree)" -if ! (echo "$TREE" | grep -Po "\"name\":\"${NAME}\".*?floating\":\"[^\"]*\"" \ +if ! (echo "$TREE" | grep -Po "\"name\":\"${W_NAME}\".*?class\":\"$W_CLASS\".*?floating\":\"[^\"]*\"" \ | grep -q '"floating":"user_on"') then EXIST_NOT=1 elif (echo "$TREE" | grep -Po '"focused":true.*?name":"[^"]*"' \ - | grep -q "\"name\":\"${NAME}\"") + | grep -q "\"name\":\"${W_NAME}\"") then FOCUS_ON_PAD=1 elif [ ! $EXIST_NOT ] && (echo "$TREE" | grep -Po '"output":"__i3".*?"name":"[^"]*"' \ - | grep -q "\"name\":\"${NAME}\"") + | grep -q "\"name\":\"${W_NAME}\"") then HIDDEN=1 fi if [ $HIDE ] && [ ! $EXIST_NOT ] && [ ! $HIDDEN ]; then # There is a visible scratchpad-terminal that shall be hidden - i3-msg "[class=\"$CLASS\" title=\"^${NAME}$\"] scratchpad show" + i3-msg "[class=\"$W_CLASS\" title=\"^${W_NAME}$\"] scratchpad show" exit 0 fi if [ $SHOW ]; then if [ $EXIST_NOT ]; then # terminal does not exist yet - gnome-terminal --window-with-profile="$NAME" --hide-menubar + # WORKSPACE="$(i3-msg -t get_workspaces | jq '.[] | select(.focused==true).name' | tr -d '"')" + # i3-msg "workspace $W_NAME, exec env SCRATCHPAD_TERMINAL=1 $COMMAND, workspace $WORKSPACE" + env SCRATCHPAD_TERMINAL=1 $COMMAND elif [ $HIDDEN ]; then # terminal is "hidden" in scratchpad - i3-msg "[class=\"$CLASS\" title=\"^${NAME}$\"] scratchpad show" + i3-msg "[class=\"$W_CLASS\" title=\"^${W_NAME}$\"] scratchpad show" elif [ ! $FOCUS_ON_PAD ]; then # terminal is visible but focus lays somewhere else - i3-msg "[class=\"$CLASS\" title=\"^${NAME}$\"] scratchpad show, scratchpad show" + i3-msg "[class=\"$W_CLASS\" title=\"^${W_NAME}$\"] scratchpad show, scratchpad show" fi exit 0 fi diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 6b69e62..749ff5a 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -1,7 +1,8 @@ ## Author: druckdev ## Created 2018-11-23 -# echo ${(pl.$LINES..\n.)} +# Set terminals title if this is a scratchpad-terminal +[ -z "$SCRATCHPAD_TERMINAL" ] || printf "\x1b\x5d\x30\x3bscratchpad-terminal\x07" # Enable Powerlevel10k instant prompt. Should stay at the top of ~/.config/zsh/.zshrc. if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then