From f40d2cd7a4d0b24956bd8fbfd47c901b99555360 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 7 Mar 2023 15:08:10 +0200 Subject: New agnostic dropdown terminal --- dropdown | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 dropdown diff --git a/dropdown b/dropdown new file mode 100755 index 0000000..b124b1a --- /dev/null +++ b/dropdown @@ -0,0 +1,67 @@ +#!/bin/bash + +# Created By: srdusr +# Created On: Tue 07 Mar 2023 15:06:47 PM CAT +# Project: Agnostic dropdown/scratchpad terminal that works on most window managers + + +# List of supported terminals with dropdown class +supported_terminals=( + "wezterm" + "kitty" + "alacritty" +) + +# Check if any of the supported terminals with dropdown class are running +for term in "${supported_terminals[@]}"; do + if pgrep -f "$term.*--class dropdown" > /dev/null; then + my_term="$term" + break + fi +done + +# If none of the supported terminals are running, start the first available one +if [ -z "$my_term" ]; then + for term in "${supported_terminals[@]}"; do + if command -v "$term" > /dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ -z "$my_term" ]; then + echo "No supported terminal found." + exit 1 + fi + + # Start the terminal with dropdown class + case "$my_term" in + "wezterm") + wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + "kitty") + kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + "alacritty") + alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + esac +fi + +# Get the window ID of the dropdown terminal +id="$(xdo id -N dropdown)" + +# Toggle the visibility of the dropdown terminal +if [ -n "$id" ]; then + if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; then + # The dropdown window is visible, so hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" + xdo hide "$id" + else + # The dropdown window is hidden, so show it + xdo show "$id" + # Restore the dimensions of the window + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" + fi +fi + + -- cgit v1.2.3 From cbc41ba76c0da3489b6162f52bc37a7225e97364 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 4 Apr 2023 04:25:14 +0200 Subject: Add vi-mode script --- vi-mode.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 vi-mode.sh diff --git a/vi-mode.sh b/vi-mode.sh new file mode 100644 index 0000000..fa1f6c6 --- /dev/null +++ b/vi-mode.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Set vi-mode and key bindings for zsh +if [[ -n "$ZSH_VERSION" ]]; then + bindkey -v + export KEYTIMEOUT=1 + + # Show which mode + function zle-keymap-select { + if [[ $KEYMAP == vicmd ]] || + [[ $1 = 'block' ]]; then + echo -n -- NORMAL -- + else + echo -n -- INSERT -- + fi + echo -ne '\n' + zle reset-prompt + } + zle -N zle-keymap-select + + # Fix backspace bug when switching modes + bindkey '^?' backward-delete-char + + # Edit line in vim with alt-e + autoload edit-command-line; zle -N edit-command-line + bindkey '^e' edit-command-line + + # Navigate in complete menu + bindkey -M menuselect 'h' vi-backward-char + bindkey -M menuselect 'j' vi-down-line-or-history + bindkey -M menuselect 'k' vi-up-line-or-history + bindkey -M menuselect 'l' vi-forward-char + + # Map 'jk' to Escape key in INSERT mode + bindkey -M insert 'jk' vi-cmd-mode + +# Set vi-mode and key bindings for bash +elif [[ -n "$BASH_VERSION" ]]; then + set -o vi + + # Show which mode + show-mode() { + if [[ "$BASH_MODE" == "vi" ]]; then + echo -ne "\[\033[1m\]-- NORMAL --\[\033[0m\]\n" + else + echo -ne "\[\033[1m\]-- INSERT --\[\033[0m\]\n" + fi + } + PS1='$(show-mode)\u@\h:\w\$ ' + + # Edit line in vim with alt-e + edit-command-line() { + local temp=$(mktemp /tmp/bash-edit-line.XXXXXXXXXX) + history -a + history -n + fc -ln -1 > "${temp}" + vim "${temp}" + READLINE_LINE=$(cat "${temp}") + READLINE_POINT=0 + rm -f "${temp}" + } + bind -x '"\ee": edit-command-line' + + # Navigate in complete menu + bind -m vi-command '"h": backward-char' # map h to backward-char + bind -m vi-command '"j": down-line-or-history' # map j to down-line-or-history + bind -m vi-command '"k": up-line-or-history' # map k to up-line-or-history + bind -m vi-command '"l": forward-char' # map l to forward-char + + # Map 'jk' to Escape key in INSERT mode + bind -m vi-insert '"jk":vi-movement-mode' + + # Fix backspace bug when switching modes + stty erase '^?' +fi + +# Reload .bashrc or .bash_profile file if using bash +if [[ -n "$BASH_VERSION" ]]; then + if [[ -f "$HOME/.bashrc" ]]; then + source ~/.bashrc + elif [[ -f "$HOME/.bash_profile" ]]; then + source ~/.bash_profile + fi +fi + +# Reload .zshrc file if using zsh +if [[ -n "$ZSH_VERSION" ]]; then + source ~/.zshrc +fi -- cgit v1.2.3 From dc19e6210735217d9659d2c0a6034ce0ce82bc86 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 4 Apr 2023 04:56:30 +0200 Subject: Better prompt (new line) for zsh --- vi-mode.sh | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/vi-mode.sh b/vi-mode.sh index fa1f6c6..d7f4e4f 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -6,16 +6,38 @@ if [[ -n "$ZSH_VERSION" ]]; then export KEYTIMEOUT=1 # Show which mode - function zle-keymap-select { - if [[ $KEYMAP == vicmd ]] || - [[ $1 = 'block' ]]; then - echo -n -- NORMAL -- - else - echo -n -- INSERT -- - fi - echo -ne '\n' - zle reset-prompt + terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1] + + function insert-mode () { echo "-- INSERT --" } + function normal-mode () { echo "-- NORMAL --" } + + precmd () { + # yes, I actually like to have a new line, then some stuff and then + # the input line + print -rP " + [%D{%a, %d %b %Y, %H:%M:%S}] %n %{$fg[blue]%}%m%{$reset_color%}" + + # this is required for initial prompt and a problem I had with Ctrl+C or + # Enter when in normal mode (a new line would come up in insert mode, + # but normal mode would be indicated) + PS1="%{$terminfo_down_sc$(insert-mode)$terminfo[rc]%}%~ $ " } + function set-prompt () { + case ${KEYMAP} in + (vicmd) VI_MODE="$(normal-mode)" ;; + (main|viins) VI_MODE="$(insert-mode)" ;; + (*) VI_MODE="$(insert-mode)" ;; + esac + PS1="%{$terminfo_down_sc$VI_MODE$terminfo[rc]%}%~ $ " + } + + function zle-line-init zle-keymap-select { + set-prompt + zle reset-prompt + } + preexec () { print -rn -- $terminfo[el]; } + + zle -N zle-line-init zle -N zle-keymap-select # Fix backspace bug when switching modes -- cgit v1.2.3 From 2f4e4b0b317dd4c864d997ee080b9d51f1692d8a Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 4 Apr 2023 04:58:13 +0200 Subject: changed incorrect syntax for mapping new escape keys --- vi-mode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vi-mode.sh b/vi-mode.sh index d7f4e4f..7e94689 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -54,7 +54,7 @@ if [[ -n "$ZSH_VERSION" ]]; then bindkey -M menuselect 'l' vi-forward-char # Map 'jk' to Escape key in INSERT mode - bindkey -M insert 'jk' vi-cmd-mode + bindkey -M viins 'jk' vi-cmd-mode # Set vi-mode and key bindings for bash elif [[ -n "$BASH_VERSION" ]]; then -- cgit v1.2.3 From 7a4e843a0bbb74f028b92b23abbaa27c468db3e7 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 3 Jun 2023 23:36:22 +0200 Subject: Fixed syntax issue for functions zle-line-init and zle-keymap-select --- vi-mode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vi-mode.sh b/vi-mode.sh index 7e94689..7776106 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -31,7 +31,7 @@ if [[ -n "$ZSH_VERSION" ]]; then PS1="%{$terminfo_down_sc$VI_MODE$terminfo[rc]%}%~ $ " } - function zle-line-init zle-keymap-select { + function zle-line-init() zle-keymap-select() { set-prompt zle reset-prompt } -- cgit v1.2.3 From 950b8a1e10ac248ab10d8b3ecde83f25167c19f1 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 3 Jun 2023 23:43:51 +0200 Subject: Still trying to fix script syntax errors --- vi-mode.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vi-mode.sh b/vi-mode.sh index 7776106..5c3678f 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -31,9 +31,10 @@ if [[ -n "$ZSH_VERSION" ]]; then PS1="%{$terminfo_down_sc$VI_MODE$terminfo[rc]%}%~ $ " } - function zle-line-init() zle-keymap-select() { + function zle-line-init () { set-prompt zle reset-prompt + zle-keymap-select } preexec () { print -rn -- $terminfo[el]; } -- cgit v1.2.3 From f010bef6b4eb0e252bde35e180d31573dfec330b Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 3 Jun 2023 23:52:57 +0200 Subject: Trying to fix elif script syntax errors --- vi-mode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vi-mode.sh b/vi-mode.sh index 5c3678f..a3f70e0 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -57,8 +57,8 @@ if [[ -n "$ZSH_VERSION" ]]; then # Map 'jk' to Escape key in INSERT mode bindkey -M viins 'jk' vi-cmd-mode -# Set vi-mode and key bindings for bash elif [[ -n "$BASH_VERSION" ]]; then + # Set vi-mode and key bindings for bash set -o vi # Show which mode -- cgit v1.2.3 From ce387ecd93f82daeb4a8cb2012687a80f55e22e9 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 00:02:36 +0200 Subject: Add else statement if unsupported shell --- vi-mode.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/vi-mode.sh b/vi-mode.sh index a3f70e0..a46f042 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -95,18 +95,20 @@ elif [[ -n "$BASH_VERSION" ]]; then # Fix backspace bug when switching modes stty erase '^?' +else + echo "Unsupported shell" fi -# Reload .bashrc or .bash_profile file if using bash -if [[ -n "$BASH_VERSION" ]]; then - if [[ -f "$HOME/.bashrc" ]]; then - source ~/.bashrc - elif [[ -f "$HOME/.bash_profile" ]]; then - source ~/.bash_profile - fi -fi - -# Reload .zshrc file if using zsh -if [[ -n "$ZSH_VERSION" ]]; then - source ~/.zshrc -fi +## Reload .bashrc or .bash_profile file if using bash +#if [[ -n "$BASH_VERSION" ]]; then +# if [[ -f "$HOME/.bashrc" ]]; then +# source ~/.bashrc +# elif [[ -f "$HOME/.bash_profile" ]]; then +# source ~/.bash_profile +# fi +#fi +# +## Reload .zshrc file if using zsh +#if [[ -n "$ZSH_VERSION" ]]; then +# source ~/.zshrc +#fi -- cgit v1.2.3 From 073645b320f47888700fb3335466603567a6b879 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 00:14:21 +0200 Subject: Make script more POSIX compliant --- vi-mode.sh | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/vi-mode.sh b/vi-mode.sh index a46f042..ae5b132 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -1,37 +1,37 @@ -#!/bin/bash +#!/bin/sh # Set vi-mode and key bindings for zsh -if [[ -n "$ZSH_VERSION" ]]; then +if [ -n "$ZSH_VERSION" ]; then bindkey -v export KEYTIMEOUT=1 # Show which mode - terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1] + terminfo_down_sc=$(tput cud1)$(tput cuu1)$(tput sc)$(tput cud1) - function insert-mode () { echo "-- INSERT --" } - function normal-mode () { echo "-- NORMAL --" } + insert-mode () { echo "-- INSERT --"; } + normal-mode () { echo "-- NORMAL --"; } precmd () { # yes, I actually like to have a new line, then some stuff and then # the input line print -rP " - [%D{%a, %d %b %Y, %H:%M:%S}] %n %{$fg[blue]%}%m%{$reset_color%}" + [%D{%a, %d %b %Y, %H:%M:%S}] %n %{${fg[blue]}%}%m%{$reset_color%}" # this is required for initial prompt and a problem I had with Ctrl+C or # Enter when in normal mode (a new line would come up in insert mode, # but normal mode would be indicated) - PS1="%{$terminfo_down_sc$(insert-mode)$terminfo[rc]%}%~ $ " + PS1="%{${terminfo_down_sc}$(insert-mode)${terminfo[rc]}%}%~ $ " } - function set-prompt () { - case ${KEYMAP} in - (vicmd) VI_MODE="$(normal-mode)" ;; - (main|viins) VI_MODE="$(insert-mode)" ;; - (*) VI_MODE="$(insert-mode)" ;; + set-prompt () { + case $KEYMAP in + vicmd) VI_MODE="$(normal-mode)" ;; + main|viins) VI_MODE="$(insert-mode)" ;; + *) VI_MODE="$(insert-mode)" ;; esac - PS1="%{$terminfo_down_sc$VI_MODE$terminfo[rc]%}%~ $ " + PS1="%{${terminfo_down_sc}${VI_MODE}${terminfo[rc]}%}%~ $ " } - function zle-line-init () { + zle-line-init () { set-prompt zle reset-prompt zle-keymap-select @@ -57,13 +57,13 @@ if [[ -n "$ZSH_VERSION" ]]; then # Map 'jk' to Escape key in INSERT mode bindkey -M viins 'jk' vi-cmd-mode -elif [[ -n "$BASH_VERSION" ]]; then +elif [ -n "$BASH_VERSION" ]; then # Set vi-mode and key bindings for bash set -o vi # Show which mode show-mode() { - if [[ "$BASH_MODE" == "vi" ]]; then + if [ "$BASH_MODE" = "vi" ]; then echo -ne "\[\033[1m\]-- NORMAL --\[\033[0m\]\n" else echo -ne "\[\033[1m\]-- INSERT --\[\033[0m\]\n" @@ -98,17 +98,3 @@ elif [[ -n "$BASH_VERSION" ]]; then else echo "Unsupported shell" fi - -## Reload .bashrc or .bash_profile file if using bash -#if [[ -n "$BASH_VERSION" ]]; then -# if [[ -f "$HOME/.bashrc" ]]; then -# source ~/.bashrc -# elif [[ -f "$HOME/.bash_profile" ]]; then -# source ~/.bash_profile -# fi -#fi -# -## Reload .zshrc file if using zsh -#if [[ -n "$ZSH_VERSION" ]]; then -# source ~/.zshrc -#fi -- cgit v1.2.3 From ca7a3f2be58af3c99ac658f49d7f20462e5a52f4 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 00:28:40 +0200 Subject: Trying to fix show-mode identifier not valid error --- vi-mode.sh | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/vi-mode.sh b/vi-mode.sh index ae5b132..6f2ce92 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -11,6 +11,14 @@ if [ -n "$ZSH_VERSION" ]; then insert-mode () { echo "-- INSERT --"; } normal-mode () { echo "-- NORMAL --"; } + show-mode() { + case $KEYMAP in + vicmd) echo "$(normal-mode)" ;; + main|viins) echo "$(insert-mode)" ;; + *) echo "$(insert-mode)" ;; + esac + } + precmd () { # yes, I actually like to have a new line, then some stuff and then # the input line @@ -20,8 +28,9 @@ if [ -n "$ZSH_VERSION" ]; then # this is required for initial prompt and a problem I had with Ctrl+C or # Enter when in normal mode (a new line would come up in insert mode, # but normal mode would be indicated) - PS1="%{${terminfo_down_sc}$(insert-mode)${terminfo[rc]}%}%~ $ " + PS1="%{${terminfo_down_sc}$(show-mode)${terminfo[rc]}%}%~ $ " } + set-prompt () { case $KEYMAP in vicmd) VI_MODE="$(normal-mode)" ;; @@ -61,7 +70,6 @@ elif [ -n "$BASH_VERSION" ]; then # Set vi-mode and key bindings for bash set -o vi - # Show which mode show-mode() { if [ "$BASH_MODE" = "vi" ]; then echo -ne "\[\033[1m\]-- NORMAL --\[\033[0m\]\n" @@ -69,32 +77,9 @@ elif [ -n "$BASH_VERSION" ]; then echo -ne "\[\033[1m\]-- INSERT --\[\033[0m\]\n" fi } + PS1='$(show-mode)\u@\h:\w\$ ' # Edit line in vim with alt-e edit-command-line() { - local temp=$(mktemp /tmp/bash-edit-line.XXXXXXXXXX) - history -a - history -n - fc -ln -1 > "${temp}" - vim "${temp}" - READLINE_LINE=$(cat "${temp}") - READLINE_POINT=0 - rm -f "${temp}" - } - bind -x '"\ee": edit-command-line' - - # Navigate in complete menu - bind -m vi-command '"h": backward-char' # map h to backward-char - bind -m vi-command '"j": down-line-or-history' # map j to down-line-or-history - bind -m vi-command '"k": up-line-or-history' # map k to up-line-or-history - bind -m vi-command '"l": forward-char' # map l to forward-char - - # Map 'jk' to Escape key in INSERT mode - bind -m vi-insert '"jk":vi-movement-mode' - - # Fix backspace bug when switching modes - stty erase '^?' -else - echo "Unsupported shell" -fi + local temp=$(mktemp /tmp/bash -- cgit v1.2.3 From ef74c4dff0667854df3d149a74d841eb6b3b2cc7 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 00:31:07 +0200 Subject: Fix EOF error --- vi-mode.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/vi-mode.sh b/vi-mode.sh index 6f2ce92..e136c32 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -82,4 +82,29 @@ elif [ -n "$BASH_VERSION" ]; then # Edit line in vim with alt-e edit-command-line() { - local temp=$(mktemp /tmp/bash + local temp=$(mktemp /tmp/bash-edit-line.XXXXXXXXXX) + history -a + history -n + fc -ln -1 > "${temp}" + vim "${temp}" + READLINE_LINE=$(cat "${temp}") + READLINE_POINT=0 + rm -f "${temp}" + } + bind -x '"\ee": edit-command-line' + + # Navigate in complete menu + bind -m vi-command '"h": backward-char' # map h to backward-char + bind -m vi-command '"j": down-line-or-history' # map j to down-line-or-history + bind -m vi-command '"k": up-line-or-history' # map k to up-line-or-history + bind -m vi-command '"l": forward-char' # map l to forward-char + + # Map 'jk' to Escape key in INSERT mode + bind -m vi-insert '"jk":vi-movement-mode' + + # Fix backspace bug when switching modes + stty erase '^?' +else + echo "Unsupported shell" +fi + -- cgit v1.2.3 From afaf628aeb3d6881213c8a846599b67ba1571346 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 00:38:36 +0200 Subject: Fix EOF error/parenthesis mismatched --- vi-mode.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vi-mode.sh b/vi-mode.sh index e136c32..75ddd3a 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -28,7 +28,7 @@ if [ -n "$ZSH_VERSION" ]; then # this is required for initial prompt and a problem I had with Ctrl+C or # Enter when in normal mode (a new line would come up in insert mode, # but normal mode would be indicated) - PS1="%{${terminfo_down_sc}$(show-mode)${terminfo[rc]}%}%~ $ " + PS1="%{${terminfo_down_sc}%$(show-mode)%${terminfo[rc]}%}%~ $ " } set-prompt () { @@ -107,4 +107,3 @@ elif [ -n "$BASH_VERSION" ]; then else echo "Unsupported shell" fi - -- cgit v1.2.3 From 1a529b17b6e52ee7aec10b66a24b1cb9d22b7633 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 00:48:10 +0200 Subject: Show-mode error --- vi-mode.sh | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/vi-mode.sh b/vi-mode.sh index 75ddd3a..46f46ec 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -11,16 +11,8 @@ if [ -n "$ZSH_VERSION" ]; then insert-mode () { echo "-- INSERT --"; } normal-mode () { echo "-- NORMAL --"; } - show-mode() { - case $KEYMAP in - vicmd) echo "$(normal-mode)" ;; - main|viins) echo "$(insert-mode)" ;; - *) echo "$(insert-mode)" ;; - esac - } - precmd () { - # yes, I actually like to have a new line, then some stuff and then + # yes, I actually like to have a new line, then some stuff and then # the input line print -rP " [%D{%a, %d %b %Y, %H:%M:%S}] %n %{${fg[blue]}%}%m%{$reset_color%}" @@ -28,7 +20,7 @@ if [ -n "$ZSH_VERSION" ]; then # this is required for initial prompt and a problem I had with Ctrl+C or # Enter when in normal mode (a new line would come up in insert mode, # but normal mode would be indicated) - PS1="%{${terminfo_down_sc}%$(show-mode)%${terminfo[rc]}%}%~ $ " + PS1="%{${terminfo_down_sc}%$(insert-mode)%${terminfo[rc]}%}%~ $ " } set-prompt () { @@ -54,7 +46,7 @@ if [ -n "$ZSH_VERSION" ]; then bindkey '^?' backward-delete-char # Edit line in vim with alt-e - autoload edit-command-line; zle -N edit-command-line + autoload -U edit-command-line; zle -N edit-command-line bindkey '^e' edit-command-line # Navigate in complete menu @@ -71,25 +63,25 @@ elif [ -n "$BASH_VERSION" ]; then set -o vi show-mode() { - if [ "$BASH_MODE" = "vi" ]; then - echo -ne "\[\033[1m\]-- NORMAL --\[\033[0m\]\n" - else - echo -ne "\[\033[1m\]-- INSERT --\[\033[0m\]\n" - fi + if [ "$BASH_MODE" = "vi" ]; then + echo -ne "\[\033[1m\]-- NORMAL --\[\033[0m\]\n" + else + echo -ne "\[\033[1m\]-- INSERT --\[\033[0m\]\n" + fi } PS1='$(show-mode)\u@\h:\w\$ ' # Edit line in vim with alt-e edit-command-line() { - local temp=$(mktemp /tmp/bash-edit-line.XXXXXXXXXX) - history -a - history -n - fc -ln -1 > "${temp}" - vim "${temp}" - READLINE_LINE=$(cat "${temp}") - READLINE_POINT=0 - rm -f "${temp}" + local temp=$(mktemp /tmp/bash-edit-line.XXXXXXXXXX) + history -a + history -n + fc -ln -1 > "${temp}" + vim "${temp}" + READLINE_LINE=$(cat "${temp}") + READLINE_POINT=0 + rm -f "${temp}" } bind -x '"\ee": edit-command-line' @@ -104,6 +96,7 @@ elif [ -n "$BASH_VERSION" ]; then # Fix backspace bug when switching modes stty erase '^?' + else - echo "Unsupported shell" + echo "Unsupported shell" fi -- cgit v1.2.3 From 1d0c9378144fe508b5d4ee5d90a3902c0626404b Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 00:59:35 +0200 Subject: Changed script to be more simpler because of non interactive shell environment --- vi-mode.sh | 111 +++++++++---------------------------------------------------- 1 file changed, 16 insertions(+), 95 deletions(-) diff --git a/vi-mode.sh b/vi-mode.sh index 46f46ec..4b3b6c2 100644 --- a/vi-mode.sh +++ b/vi-mode.sh @@ -1,102 +1,23 @@ #!/bin/sh -# Set vi-mode and key bindings for zsh -if [ -n "$ZSH_VERSION" ]; then - bindkey -v - export KEYTIMEOUT=1 - - # Show which mode - terminfo_down_sc=$(tput cud1)$(tput cuu1)$(tput sc)$(tput cud1) - - insert-mode () { echo "-- INSERT --"; } - normal-mode () { echo "-- NORMAL --"; } - - precmd () { - # yes, I actually like to have a new line, then some stuff and then - # the input line - print -rP " - [%D{%a, %d %b %Y, %H:%M:%S}] %n %{${fg[blue]}%}%m%{$reset_color%}" - - # this is required for initial prompt and a problem I had with Ctrl+C or - # Enter when in normal mode (a new line would come up in insert mode, - # but normal mode would be indicated) - PS1="%{${terminfo_down_sc}%$(insert-mode)%${terminfo[rc]}%}%~ $ " - } - - set-prompt () { - case $KEYMAP in - vicmd) VI_MODE="$(normal-mode)" ;; - main|viins) VI_MODE="$(insert-mode)" ;; - *) VI_MODE="$(insert-mode)" ;; - esac - PS1="%{${terminfo_down_sc}${VI_MODE}${terminfo[rc]}%}%~ $ " - } - - zle-line-init () { - set-prompt - zle reset-prompt - zle-keymap-select - } - preexec () { print -rn -- $terminfo[el]; } - - zle -N zle-line-init - zle -N zle-keymap-select - - # Fix backspace bug when switching modes - bindkey '^?' backward-delete-char - - # Edit line in vim with alt-e - autoload -U edit-command-line; zle -N edit-command-line - bindkey '^e' edit-command-line - - # Navigate in complete menu - bindkey -M menuselect 'h' vi-backward-char - bindkey -M menuselect 'j' vi-down-line-or-history - bindkey -M menuselect 'k' vi-up-line-or-history - bindkey -M menuselect 'l' vi-forward-char - - # Map 'jk' to Escape key in INSERT mode - bindkey -M viins 'jk' vi-cmd-mode +# Show which mode +insert_mode="-- INSERT --" +normal_mode="-- NORMAL --" +if [ -n "$ZSH_VERSION" ]; then + if [[ $KEYMAP == 'vicmd' ]]; then + VI_MODE=$normal_mode + else + VI_MODE=$insert_mode + fi + printf "%s\n" "$VI_MODE" elif [ -n "$BASH_VERSION" ]; then - # Set vi-mode and key bindings for bash - set -o vi - - show-mode() { - if [ "$BASH_MODE" = "vi" ]; then - echo -ne "\[\033[1m\]-- NORMAL --\[\033[0m\]\n" - else - echo -ne "\[\033[1m\]-- INSERT --\[\033[0m\]\n" - fi - } - - PS1='$(show-mode)\u@\h:\w\$ ' - - # Edit line in vim with alt-e - edit-command-line() { - local temp=$(mktemp /tmp/bash-edit-line.XXXXXXXXXX) - history -a - history -n - fc -ln -1 > "${temp}" - vim "${temp}" - READLINE_LINE=$(cat "${temp}") - READLINE_POINT=0 - rm -f "${temp}" - } - bind -x '"\ee": edit-command-line' - - # Navigate in complete menu - bind -m vi-command '"h": backward-char' # map h to backward-char - bind -m vi-command '"j": down-line-or-history' # map j to down-line-or-history - bind -m vi-command '"k": up-line-or-history' # map k to up-line-or-history - bind -m vi-command '"l": forward-char' # map l to forward-char - - # Map 'jk' to Escape key in INSERT mode - bind -m vi-insert '"jk":vi-movement-mode' - - # Fix backspace bug when switching modes - stty erase '^?' - + if [[ $BASH_MODE == 'vi' ]]; then + VI_MODE=$normal_mode + else + VI_MODE=$insert_mode + fi + printf "%s\n" "$VI_MODE" else echo "Unsupported shell" fi -- cgit v1.2.3 From ee5a4e281ad7bca6ba581bf4fdbe542b6f62c0ab Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 4 Jun 2023 01:11:13 +0200 Subject: Removed vi-mode.sh --- vi-mode.sh | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 vi-mode.sh diff --git a/vi-mode.sh b/vi-mode.sh deleted file mode 100644 index 4b3b6c2..0000000 --- a/vi-mode.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# Show which mode -insert_mode="-- INSERT --" -normal_mode="-- NORMAL --" - -if [ -n "$ZSH_VERSION" ]; then - if [[ $KEYMAP == 'vicmd' ]]; then - VI_MODE=$normal_mode - else - VI_MODE=$insert_mode - fi - printf "%s\n" "$VI_MODE" -elif [ -n "$BASH_VERSION" ]; then - if [[ $BASH_MODE == 'vi' ]]; then - VI_MODE=$normal_mode - else - VI_MODE=$insert_mode - fi - printf "%s\n" "$VI_MODE" -else - echo "Unsupported shell" -fi -- cgit v1.2.3 From 4de87c9813be65b096db5962101e2d4f4f310dde Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 14 Jul 2023 19:52:57 +0200 Subject: Install nvim in Windows (bat/cmd) --- win-nvim.bat | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 win-nvim.bat diff --git a/win-nvim.bat b/win-nvim.bat new file mode 100644 index 0000000..3439ffb --- /dev/null +++ b/win-nvim.bat @@ -0,0 +1,31 @@ +@echo off + +REM Install NeoVim with winget, if not already present on the system +where nvim >nul 2>nul +if %errorlevel% neq 0 ( + winget install Neovim.Neovim -q +) + +REM Clone my dotfiles repo +set dotFilesRoot=%USERPROFILE%\dotfiles +if not exist "%dotFilesRoot%\." ( + git clone git@github.com:srdusr/dotfiles.git "%dotFilesRoot%" +) + +REM Link NeoVim configuration +set localConfiguration=%LOCALAPPDATA%\nvim +set dotfilesConfiguration=%dotFilesRoot%\.config\nvim + +if not exist "%localConfiguration%\." ( + mklink /D "%localConfiguration%" "%dotfilesConfiguration%" +) + +REM Clone Packer.nvim, if not already present on the system +set localPacker=%LOCALAPPDATA%\nvim-data\site\pack\packer\start\packer.nvim + +if not exist "%localPacker%\." ( + git clone https://github.com/wbthomason/packer.nvim "%localPacker%" +) + +REM Run the script by using this command in the same existing directory: win-nvim.bat + -- cgit v1.2.3 From 47fd8530ddaeac3398c240794518ad5247fd5d28 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 14 Jul 2023 19:53:25 +0200 Subject: Install nvim in Windows (psh) --- win-nvim.ps1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 win-nvim.ps1 diff --git a/win-nvim.ps1 b/win-nvim.ps1 new file mode 100644 index 0000000..82a454b --- /dev/null +++ b/win-nvim.ps1 @@ -0,0 +1,31 @@ +# Install NeoVim with winget, if not already present on the system +if (!(Get-Command nvim -ErrorAction SilentlyContinue)) { + winget install Neovim.Neovim +} + +# Clone my dotfiles repo +$dotFilesRoot = Join-Path $HOME "dotfiles" + +if (!(Test-Path $dotFilesRoot -PathType Container)) { + git clone git@github.com:srdusr/dotfiles.git $dotFilesRoot +} + +# Link NeoVim configuration +$localConfiguration = Join-Path $env:LOCALAPPDATA "nvim" +$dotfilesConfiguration = Join-Path $dotFilesRoot ".config" "nvim" + +if (!(Test-Path $localConfiguration -PathType Container)) { + Start-Process -FilePath "cmd.exe" -ArgumentList "/c mklink /D $localConfiguration $dotfilesConfiguration" -Verb runas +} + +# Clone Packer.nvim, if not already present on the system +$localPacker = Join-Path $env:LOCALAPPDATA "nvim-data" "site" "pack" "packer" "start" "packer.nvim" + +if (!(Test-Path $localPacker -PathType Container)) { + git clone https://github.com/wbthomason/packer.nvim $localPacker +} + +# To allow script execution, run the following command in PowerShell as an administrator: +# Set-ExecutionPolicy RemoteSigned +# Then run the script by using this command in the same existing directory: +# ./win-nvim.ps1 -- cgit v1.2.3 From 32a71a6f19b45a00b3ea80f5698a2e460769f1e4 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:00:36 +0200 Subject: Changed from ssh to https --- win-nvim.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 82a454b..4f156ec 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -7,7 +7,7 @@ if (!(Get-Command nvim -ErrorAction SilentlyContinue)) { $dotFilesRoot = Join-Path $HOME "dotfiles" if (!(Test-Path $dotFilesRoot -PathType Container)) { - git clone git@github.com:srdusr/dotfiles.git $dotFilesRoot + git clone https://github.com:srdusr/dotfiles.git $dotFilesRoot } # Link NeoVim configuration @@ -29,3 +29,11 @@ if (!(Test-Path $localPacker -PathType Container)) { # Set-ExecutionPolicy RemoteSigned # Then run the script by using this command in the same existing directory: # ./win-nvim.ps1 +curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle +powershell Add-AppxPackage -Path "winget-cli.appxbundle" +Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) +use `-y` or consider: choco feature enable -n allowGlobalConfirmation +choco install git +- Refresh the environment +Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 +refreshenv -- cgit v1.2.3 From 471027875eb344cd733aec4951e31d1d9eeabf02 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:04:21 +0200 Subject: Fixed slight syntax error on git clone --- win-nvim.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 4f156ec..608a297 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -7,7 +7,7 @@ if (!(Get-Command nvim -ErrorAction SilentlyContinue)) { $dotFilesRoot = Join-Path $HOME "dotfiles" if (!(Test-Path $dotFilesRoot -PathType Container)) { - git clone https://github.com:srdusr/dotfiles.git $dotFilesRoot + git clone https://github.com/srdusr/dotfiles.git $dotFilesRoot } # Link NeoVim configuration -- cgit v1.2.3 From 933e5894500b3e0101482ed6b168374ae0739158 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:13:17 +0200 Subject: Testing, accidental comments not commented --- win-nvim.ps1 | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 608a297..2ca2509 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -29,11 +29,25 @@ if (!(Test-Path $localPacker -PathType Container)) { # Set-ExecutionPolicy RemoteSigned # Then run the script by using this command in the same existing directory: # ./win-nvim.ps1 -curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle -powershell Add-AppxPackage -Path "winget-cli.appxbundle" -Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) -use `-y` or consider: choco feature enable -n allowGlobalConfirmation -choco install git -- Refresh the environment -Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 -refreshenv +#curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle +#powershell Add-AppxPackage -Path "winget-cli.appxbundle" +#Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) +#use `-y` or consider: choco feature enable -n allowGlobalConfirmation +#choco install git +#- Refresh the environment +#Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 +#refreshenv +# +# +#here is the error +#At C:\Users\grayt\scripts\win-nvim.ps1:37 char:2 +#+ - Refresh the environment +#+ ~ +#Missing expression after unary operator '-' +#At C:\Users\grayt\scripts\win-nvim.ps1:37 char:3 +#+ - Refresh the environment +#+ ~~~~~~~~ +#Unexpected token 'Refresh' in expression or statement. +# + CategoryInfo : ParserError: (:) [], ParseException +# + FullyQualifiedErrorId : MissingExpressionAfterOperator + -- cgit v1.2.3 From 6963a31d8878a4b644412745f6962260362141f6 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:17:47 +0200 Subject: Fixed join-path --- win-nvim.ps1 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 2ca2509..1e208d7 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -1,3 +1,8 @@ +# Install Git (if not already present on the system) +if (!(Get-Command git -ErrorAction SilentlyContinue)) { + winget install Git.Git +} + # Install NeoVim with winget, if not already present on the system if (!(Get-Command nvim -ErrorAction SilentlyContinue)) { winget install Neovim.Neovim @@ -12,10 +17,10 @@ if (!(Test-Path $dotFilesRoot -PathType Container)) { # Link NeoVim configuration $localConfiguration = Join-Path $env:LOCALAPPDATA "nvim" -$dotfilesConfiguration = Join-Path $dotFilesRoot ".config" "nvim" +$dotfilesConfiguration = Join-Path (Join-Path $dotFilesRoot ".config") "nvim" if (!(Test-Path $localConfiguration -PathType Container)) { - Start-Process -FilePath "cmd.exe" -ArgumentList "/c mklink /D $localConfiguration $dotfilesConfiguration" -Verb runas + Start-Process -FilePath "cmd.exe" -ArgumentList "/c mklink /D `"$localConfiguration`" `"$dotfilesConfiguration`"" -Verb runas } # Clone Packer.nvim, if not already present on the system @@ -25,6 +30,11 @@ if (!(Test-Path $localPacker -PathType Container)) { git clone https://github.com/wbthomason/packer.nvim $localPacker } +# To allow script execution, run the following command in PowerShell as an administrator: +# Set-ExecutionPolicy RemoteSigned +# Then run the script by using this command in the same existing directory: +# ./win-nvim.ps1 + # To allow script execution, run the following command in PowerShell as an administrator: # Set-ExecutionPolicy RemoteSigned # Then run the script by using this command in the same existing directory: @@ -50,4 +60,3 @@ if (!(Test-Path $localPacker -PathType Container)) { #Unexpected token 'Refresh' in expression or statement. # + CategoryInfo : ParserError: (:) [], ParseException # + FullyQualifiedErrorId : MissingExpressionAfterOperator - -- cgit v1.2.3 From 517bdf668bc8bc48bd5d06073b142db40fe81ea4 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:20:46 +0200 Subject: Fixed more join-path errors --- win-nvim.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 1e208d7..345ef58 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -20,11 +20,11 @@ $localConfiguration = Join-Path $env:LOCALAPPDATA "nvim" $dotfilesConfiguration = Join-Path (Join-Path $dotFilesRoot ".config") "nvim" if (!(Test-Path $localConfiguration -PathType Container)) { - Start-Process -FilePath "cmd.exe" -ArgumentList "/c mklink /D `"$localConfiguration`" `"$dotfilesConfiguration`"" -Verb runas + cmd /c "mklink /D `"$localConfiguration`" `"$dotfilesConfiguration`"" | Out-Null } # Clone Packer.nvim, if not already present on the system -$localPacker = Join-Path $env:LOCALAPPDATA "nvim-data" "site" "pack" "packer" "start" "packer.nvim" +$localPacker = Join-Path $env:LOCALAPPDATA "nvim" "pack" "packer" "start" "packer.nvim" if (!(Test-Path $localPacker -PathType Container)) { git clone https://github.com/wbthomason/packer.nvim $localPacker -- cgit v1.2.3 From 6a1c7625f721760f6c8e0cf988e345adbcb49e81 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:23:42 +0200 Subject: Still fixing path errors --- win-nvim.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 345ef58..800ebc1 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -34,7 +34,6 @@ if (!(Test-Path $localPacker -PathType Container)) { # Set-ExecutionPolicy RemoteSigned # Then run the script by using this command in the same existing directory: # ./win-nvim.ps1 - # To allow script execution, run the following command in PowerShell as an administrator: # Set-ExecutionPolicy RemoteSigned # Then run the script by using this command in the same existing directory: -- cgit v1.2.3 From 5cf41cf80ec1df5c0df9463ba39b86c00fad2207 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:28:04 +0200 Subject: Fixed path errors --- win-nvim.ps1 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 800ebc1..0446526 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -17,27 +17,24 @@ if (!(Test-Path $dotFilesRoot -PathType Container)) { # Link NeoVim configuration $localConfiguration = Join-Path $env:LOCALAPPDATA "nvim" -$dotfilesConfiguration = Join-Path (Join-Path $dotFilesRoot ".config") "nvim" +$dotfilesConfiguration = Join-Path $dotFilesRoot ".config" "nvim" if (!(Test-Path $localConfiguration -PathType Container)) { cmd /c "mklink /D `"$localConfiguration`" `"$dotfilesConfiguration`"" | Out-Null } # Clone Packer.nvim, if not already present on the system -$localPacker = Join-Path $env:LOCALAPPDATA "nvim" "pack" "packer" "start" "packer.nvim" +$packerDirectory = Join-Path $env:LOCALAPPDATA "nvim" "pack" "packer" "opt" "packer.nvim" -if (!(Test-Path $localPacker -PathType Container)) { - git clone https://github.com/wbthomason/packer.nvim $localPacker +if (!(Test-Path $packerDirectory -PathType Container)) { + git clone https://github.com/wbthomason/packer.nvim $packerDirectory } # To allow script execution, run the following command in PowerShell as an administrator: # Set-ExecutionPolicy RemoteSigned # Then run the script by using this command in the same existing directory: # ./win-nvim.ps1 -# To allow script execution, run the following command in PowerShell as an administrator: -# Set-ExecutionPolicy RemoteSigned -# Then run the script by using this command in the same existing directory: -# ./win-nvim.ps1 + #curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle #powershell Add-AppxPackage -Path "winget-cli.appxbundle" #Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) -- cgit v1.2.3 From 20e7ae4a8c067151ace0cb4de36a3e9a45ef092e Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 16 Jul 2023 06:52:53 +0200 Subject: Revert back to original --- win-nvim.ps1 | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/win-nvim.ps1 b/win-nvim.ps1 index 0446526..ca67755 100644 --- a/win-nvim.ps1 +++ b/win-nvim.ps1 @@ -1,8 +1,3 @@ -# Install Git (if not already present on the system) -if (!(Get-Command git -ErrorAction SilentlyContinue)) { - winget install Git.Git -} - # Install NeoVim with winget, if not already present on the system if (!(Get-Command nvim -ErrorAction SilentlyContinue)) { winget install Neovim.Neovim @@ -20,21 +15,20 @@ $localConfiguration = Join-Path $env:LOCALAPPDATA "nvim" $dotfilesConfiguration = Join-Path $dotFilesRoot ".config" "nvim" if (!(Test-Path $localConfiguration -PathType Container)) { - cmd /c "mklink /D `"$localConfiguration`" `"$dotfilesConfiguration`"" | Out-Null + Start-Process -FilePath "cmd.exe" -ArgumentList "/c mklink /D $localConfiguration $dotfilesConfiguration" -Verb runas } # Clone Packer.nvim, if not already present on the system -$packerDirectory = Join-Path $env:LOCALAPPDATA "nvim" "pack" "packer" "opt" "packer.nvim" +$localPacker = Join-Path $env:LOCALAPPDATA "nvim-data" "site" "pack" "packer" "start" "packer.nvim" -if (!(Test-Path $packerDirectory -PathType Container)) { - git clone https://github.com/wbthomason/packer.nvim $packerDirectory +if (!(Test-Path $localPacker -PathType Container)) { + git clone https://github.com/wbthomason/packer.nvim $localPacker } # To allow script execution, run the following command in PowerShell as an administrator: # Set-ExecutionPolicy RemoteSigned # Then run the script by using this command in the same existing directory: # ./win-nvim.ps1 - #curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle #powershell Add-AppxPackage -Path "winget-cli.appxbundle" #Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) @@ -43,16 +37,3 @@ if (!(Test-Path $packerDirectory -PathType Container)) { #- Refresh the environment #Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 #refreshenv -# -# -#here is the error -#At C:\Users\grayt\scripts\win-nvim.ps1:37 char:2 -#+ - Refresh the environment -#+ ~ -#Missing expression after unary operator '-' -#At C:\Users\grayt\scripts\win-nvim.ps1:37 char:3 -#+ - Refresh the environment -#+ ~~~~~~~~ -#Unexpected token 'Refresh' in expression or statement. -# + CategoryInfo : ParserError: (:) [], ParseException -# + FullyQualifiedErrorId : MissingExpressionAfterOperator -- cgit v1.2.3 From 37b6523b18b9b5c3f7ca081d8ae01cf037b57c41 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 28 Jul 2023 21:47:24 +0200 Subject: Try to fix the script to work in DEs like gnome(mutter) --- dropdown | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 15 deletions(-) diff --git a/dropdown b/dropdown index b124b1a..856ae92 100755 --- a/dropdown +++ b/dropdown @@ -4,6 +4,68 @@ # Created On: Tue 07 Mar 2023 15:06:47 PM CAT # Project: Agnostic dropdown/scratchpad terminal that works on most window managers +## List of supported terminals with dropdown class +#supported_terminals=( +# "wezterm" +# "kitty" +# "alacritty" +#) +# +## Check if any of the supported terminals with dropdown class are running +#for term in "${supported_terminals[@]}"; do +# if pgrep -f "$term.*--class dropdown" > /dev/null; then +# my_term="$term" +# break +# fi +#done +# +## If none of the supported terminals are running, start the first available one +#if [ -z "$my_term" ]; then +# for term in "${supported_terminals[@]}"; do +# if command -v "$term" > /dev/null 2>&1; then +# my_term="$term" +# break +# fi +# done +# if [ -z "$my_term" ]; then +# echo "No supported terminal found." +# exit 1 +# fi +# +# # Start the terminal with dropdown class +# case "$my_term" in +# "wezterm") +# wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & +# ;; +# "kitty") +# kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & +# ;; +# "alacritty") +# alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & +# ;; +# esac +#fi +# +## Get the window ID of the dropdown terminal +#id="$(xdo id -N dropdown)" +# +## Toggle the visibility of the dropdown terminal +#if [ -n "$id" ]; then +# if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; then +# # The dropdown window is visible, so hide it +# dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" +# xdo hide "$id" 2>/dev/null +# else +# # The dropdown window is hidden, so show it +# xdo show "$id" +# # Restore the dimensions of the window +# xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null +# fi +#fi + + + + # List of supported terminals with dropdown class supported_terminals=( @@ -12,6 +74,26 @@ supported_terminals=( "alacritty" ) +# Function to check if the terminal is running and visible +is_terminal_visible() { + local id="$(xdotool search --class "$1" | head -1)" + [ -n "$id" ] && xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null +} + +# Function to toggle the visibility of the dropdown terminal +toggle_dropdown() { + local id="$(xdotool search --class dropdown | head -1)" + if [ -n "$id" ]; then + if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; then + # The dropdown window is visible, so hide it + xdotool windowunmap "$id" + else + # The dropdown window is hidden, so show it + xdotool windowmap "$id" + fi + fi +} + # Check if any of the supported terminals with dropdown class are running for term in "${supported_terminals[@]}"; do if pgrep -f "$term.*--class dropdown" > /dev/null; then @@ -47,21 +129,16 @@ if [ -z "$my_term" ]; then esac fi -# Get the window ID of the dropdown terminal -id="$(xdo id -N dropdown)" - -# Toggle the visibility of the dropdown terminal -if [ -n "$id" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; then - # The dropdown window is visible, so hide it - dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" - xdo hide "$id" - else - # The dropdown window is hidden, so show it - xdo show "$id" - # Restore the dimensions of the window - xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" - fi +# Check if the script is already running and exit if it is +if pgrep -x "$(basename "$0")" | grep -v $$ > /dev/null; then + exit 1 fi +# Toggle the dropdown terminal visibility +toggle_dropdown +# Set up a listener to hide the dropdown terminal when it loses focus +dropdown_id="$(xdotool search --class dropdown | head -1)" +if [ -n "$dropdown_id" ]; then + xdotool behave $dropdown_id focus-out exec "xdotool windowunmap $dropdown_id" +fi -- cgit v1.2.3 From 8398c1203459a328f9249f0f4800c0211521856b Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 28 Jul 2023 21:59:54 +0200 Subject: Attempt to fix for gnome --- dropdown | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/dropdown b/dropdown index 856ae92..13e4b69 100755 --- a/dropdown +++ b/dropdown @@ -67,6 +67,7 @@ + # List of supported terminals with dropdown class supported_terminals=( "wezterm" @@ -74,26 +75,6 @@ supported_terminals=( "alacritty" ) -# Function to check if the terminal is running and visible -is_terminal_visible() { - local id="$(xdotool search --class "$1" | head -1)" - [ -n "$id" ] && xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null -} - -# Function to toggle the visibility of the dropdown terminal -toggle_dropdown() { - local id="$(xdotool search --class dropdown | head -1)" - if [ -n "$id" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; then - # The dropdown window is visible, so hide it - xdotool windowunmap "$id" - else - # The dropdown window is hidden, so show it - xdotool windowmap "$id" - fi - fi -} - # Check if any of the supported terminals with dropdown class are running for term in "${supported_terminals[@]}"; do if pgrep -f "$term.*--class dropdown" > /dev/null; then @@ -129,16 +110,29 @@ if [ -z "$my_term" ]; then esac fi +# Function to toggle the visibility of the dropdown terminal +toggle_dropdown() { + local id="$(xdotool search --class dropdown | head -1)" + if [ -n "$id" ]; then + local state="$(xprop -id "$id" | grep "_NET_WM_STATE_HIDDEN")" + if [ -n "$state" ]; then + # The dropdown window is hidden, so show it + wmctrl -i -r "$id" -b remove,hidden + else + # The dropdown window is visible, so hide it + wmctrl -i -r "$id" -b add,hidden + fi + fi +} + # Check if the script is already running and exit if it is if pgrep -x "$(basename "$0")" | grep -v $$ > /dev/null; then exit 1 fi -# Toggle the dropdown terminal visibility +# Attempt to toggle the dropdown terminal toggle_dropdown -# Set up a listener to hide the dropdown terminal when it loses focus -dropdown_id="$(xdotool search --class dropdown | head -1)" -if [ -n "$dropdown_id" ]; then - xdotool behave $dropdown_id focus-out exec "xdotool windowunmap $dropdown_id" -fi +# Sometimes, it may fail to toggle, so we add a slight delay and try again +sleep 0.1 +toggle_dropdown -- cgit v1.2.3 From ef0e1527a73749497592464e4201bd302d6010c5 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 28 Jul 2023 22:24:04 +0200 Subject: Trying to add support for wayland --- dropdown | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/dropdown b/dropdown index 13e4b69..c4a3fa4 100755 --- a/dropdown +++ b/dropdown @@ -64,9 +64,15 @@ #fi - - - +# Function to get window ID by window class name +get_window_id_by_class() { + local class="$1" + if command -v ydotool > /dev/null; then + ydotool search --classname "$class" + elif command -v xdotool > /dev/null; then + xdotool search --classname "$class" + fi +} # List of supported terminals with dropdown class supported_terminals=( @@ -99,7 +105,7 @@ if [ -z "$my_term" ]; then # Start the terminal with dropdown class case "$my_term" in "wezterm") - wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + wezterm --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & ;; "kitty") kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & @@ -110,29 +116,26 @@ if [ -z "$my_term" ]; then esac fi -# Function to toggle the visibility of the dropdown terminal -toggle_dropdown() { - local id="$(xdotool search --class dropdown | head -1)" - if [ -n "$id" ]; then - local state="$(xprop -id "$id" | grep "_NET_WM_STATE_HIDDEN")" - if [ -n "$state" ]; then - # The dropdown window is hidden, so show it - wmctrl -i -r "$id" -b remove,hidden +# Get the window ID of the dropdown terminal using either ydotool or xdotool +id=$(get_window_id_by_class "dropdown") + +# Toggle the visibility of the dropdown terminal +if [ -n "$id" ]; then + if command -v ydotool > /dev/null; then + if ydotool windowvisible "$id"; then + # The dropdown window is visible, so hide it + ydotool windowunmap "$id" else + # The dropdown window is hidden, so show it + ydotool windowmap "$id" + fi + elif command -v xdotool > /dev/null; then + if xdotool getwindowfocus | grep -q "$id"; then # The dropdown window is visible, so hide it - wmctrl -i -r "$id" -b add,hidden + xdotool windowunmap "$id" + else + # The dropdown window is hidden, so show it + xdotool windowmap "$id" fi fi -} - -# Check if the script is already running and exit if it is -if pgrep -x "$(basename "$0")" | grep -v $$ > /dev/null; then - exit 1 fi - -# Attempt to toggle the dropdown terminal -toggle_dropdown - -# Sometimes, it may fail to toggle, so we add a slight delay and try again -sleep 0.1 -toggle_dropdown -- cgit v1.2.3 From 416377aa88cfbc17f3778cb42b8e8ad02b399921 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 28 Jul 2023 23:28:45 +0200 Subject: Update correct ydotool commands --- dropdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dropdown b/dropdown index c4a3fa4..69c734d 100755 --- a/dropdown +++ b/dropdown @@ -64,6 +64,7 @@ #fi + # Function to get window ID by window class name get_window_id_by_class() { local class="$1" @@ -122,7 +123,8 @@ id=$(get_window_id_by_class "dropdown") # Toggle the visibility of the dropdown terminal if [ -n "$id" ]; then if command -v ydotool > /dev/null; then - if ydotool windowvisible "$id"; then + mapped=$(ydotool windowmap --query "$id" | awk '{print $2}') + if [ "$mapped" = "true" ]; then # The dropdown window is visible, so hide it ydotool windowunmap "$id" else -- cgit v1.2.3 From bfe312e506f559fb1aec42e31c0842f6eb09c0d5 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 1 Aug 2023 15:07:52 +0200 Subject: Using wmctrl in hopes to toggle in wayland --- dropdown | 126 ++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 96 insertions(+), 30 deletions(-) diff --git a/dropdown b/dropdown index 69c734d..68b8816 100755 --- a/dropdown +++ b/dropdown @@ -63,17 +63,81 @@ # fi #fi - - -# Function to get window ID by window class name -get_window_id_by_class() { - local class="$1" - if command -v ydotool > /dev/null; then - ydotool search --classname "$class" - elif command -v xdotool > /dev/null; then - xdotool search --classname "$class" - fi -} +## Function to get window ID by window class name +#get_window_id_by_class() { +# local class="$1" +# if command -v ydotool >/dev/null; then +# ydotool search --classname "$class" +# elif command -v xdotool >/dev/null; then +# xdotool search --classname "$class" +# fi +#} +# +## List of supported terminals with dropdown class +#supported_terminals=( +# "wezterm" +# "kitty" +# "alacritty" +#) +# +## Check if any of the supported terminals with dropdown class are running +#for term in "${supported_terminals[@]}"; do +# if pgrep -f "$term.*--class dropdown" >/dev/null; then +# my_term="$term" +# break +# fi +#done +# +## If none of the supported terminals are running, start the first available one +#if [ "$my_term" = "" ]; then +# for term in "${supported_terminals[@]}"; do +# if command -v "$term" >/dev/null 2>&1; then +# my_term="$term" +# break +# fi +# done +# if [ "$my_term" = "" ]; then +# echo "No supported terminal found." +# exit 1 +# fi +# +# # Start the terminal with dropdown class +# case "$my_term" in +# "wezterm") +# wezterm --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & +# ;; +# "kitty") +# kitty --class dropdown tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & +# ;; +# "alacritty") +# alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & +# ;; +# esac +#fi +# +## Get the window ID of the dropdown terminal using either ydotool or xdotool +#id=$(get_window_id_by_class "dropdown") +# +## Toggle the visibility of the dropdown terminal +#if [ "$id" != "" ]; then +# if command -v ydotool >/dev/null; then +# if ydotool windowvisible "$id"; then +# # The dropdown window is visible, so hide it +# ydotool windowunmap "$id" +# else +# # The dropdown window is hidden, so show it +# ydotool windowmap "$id" +# fi +# elif command -v xdotool >/dev/null; then +# if xdotool getwindowfocus | grep -q "$id"; then +# # The dropdown window is visible, so hide it +# xdotool windowunmap "$id" +# else +# # The dropdown window is hidden, so show it +# xdotool windowmap "$id" +# fi +# fi +#fi # List of supported terminals with dropdown class supported_terminals=( @@ -106,7 +170,7 @@ if [ -z "$my_term" ]; then # Start the terminal with dropdown class case "$my_term" in "wezterm") - wezterm --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & ;; "kitty") kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & @@ -117,27 +181,29 @@ if [ -z "$my_term" ]; then esac fi -# Get the window ID of the dropdown terminal using either ydotool or xdotool -id=$(get_window_id_by_class "dropdown") +# Function to toggle the visibility of the dropdown terminal +toggle_dropdown() { + # Get the window ID of the dropdown terminal + id="$(wmctrl -l | grep "dropdown" | awk '{print $1}')" -# Toggle the visibility of the dropdown terminal -if [ -n "$id" ]; then - if command -v ydotool > /dev/null; then - mapped=$(ydotool windowmap --query "$id" | awk '{print $2}') - if [ "$mapped" = "true" ]; then - # The dropdown window is visible, so hide it - ydotool windowunmap "$id" - else + # Toggle the visibility of the dropdown terminal + if [ -n "$id" ]; then + state="$(wmctrl -l -G -p -x | grep "$id" | awk '{print $4}')" + if [ "$state" = "-1" ]; then # The dropdown window is hidden, so show it - ydotool windowmap "$id" - fi - elif command -v xdotool > /dev/null; then - if xdotool getwindowfocus | grep -q "$id"; then - # The dropdown window is visible, so hide it - xdotool windowunmap "$id" + wmctrl -i -r "$id" -b remove,hidden else - # The dropdown window is hidden, so show it - xdotool windowmap "$id" + # The dropdown window is visible, so hide it + wmctrl -i -r "$id" -b add,hidden fi fi +} + +# Check if wmctrl is available +if command -v wmctrl > /dev/null 2>&1; then + toggle_dropdown +else + echo "Window manipulation requires wmctrl. Install it and try again." + exit 1 fi + -- cgit v1.2.3 From 4595be05ff14bca88141394d1a6e52d9c417e317 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 1 Aug 2023 15:32:24 +0200 Subject: Adjustments to script (wmctrl function) --- dropdown | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dropdown b/dropdown index 68b8816..eb8f697 100755 --- a/dropdown +++ b/dropdown @@ -181,8 +181,9 @@ if [ -z "$my_term" ]; then esac fi -# Function to toggle the visibility of the dropdown terminal -toggle_dropdown() { + +# Check if wmctrl is available +if command -v wmctrl > /dev/null 2>&1; then # Get the window ID of the dropdown terminal id="$(wmctrl -l | grep "dropdown" | awk '{print $1}')" @@ -197,11 +198,6 @@ toggle_dropdown() { wmctrl -i -r "$id" -b add,hidden fi fi -} - -# Check if wmctrl is available -if command -v wmctrl > /dev/null 2>&1; then - toggle_dropdown else echo "Window manipulation requires wmctrl. Install it and try again." exit 1 -- cgit v1.2.3 From aefd78cedc43ca70b1f589df8ad1ca5bcbe42ddc Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 1 Aug 2023 15:37:58 +0200 Subject: Add termy --- termy | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 termy diff --git a/termy b/termy new file mode 100644 index 0000000..c207800 --- /dev/null +++ b/termy @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# if app is not open then launch it -- remove this if you don't want your +# shortcut to launch the application if it hasn't been launched yet +if [ -z "$(xdotool search --class konsole)" ]; then + konsole +fi + +# get current focused window and visible konsole window +CLASS="konsole" +ACTIVE_WINDOW="$(xdotool getactivewindow)" +APP_WINDOW="$(xdotool search --onlyvisible --class $CLASS)" + +# if focused, minimize and hide the konsole, otherwise bring konsole to current desktop and open +if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then + xdotool getactivewindow windowminimize +else + wmctrl -xR "$CLASS" +fi + -- cgit v1.2.3 From 19269d403be4d4d3224723f989c9356c89bdd464 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 1 Aug 2023 15:54:04 +0200 Subject: Hopeful with this solution --- dropdown | 185 +++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 63 deletions(-) diff --git a/dropdown b/dropdown index eb8f697..768bda0 100755 --- a/dropdown +++ b/dropdown @@ -4,6 +4,65 @@ # Created On: Tue 07 Mar 2023 15:06:47 PM CAT # Project: Agnostic dropdown/scratchpad terminal that works on most window managers +# List of supported terminals with dropdown class +supported_terminals=( + "wezterm" + "kitty" + "alacritty" +) + +# Check if any of the supported terminals with dropdown class are running +for term in "${supported_terminals[@]}"; do + if pgrep -f "$term.*--class dropdown" > /dev/null; then + my_term="$term" + break + fi +done + +# If none of the supported terminals are running, start the first available one +if [ -z "$my_term" ]; then + for term in "${supported_terminals[@]}"; do + if command -v "$term" > /dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ -z "$my_term" ]; then + echo "No supported terminal found." + exit 1 + fi + + # Start the terminal with dropdown class + case "$my_term" in + "wezterm") + wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + "kitty") + kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + "alacritty") + alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + esac +fi + + +# Toggle the visibility of the dropdown terminal +#if [ -n "$id" ]; then +if [ -z "$(xdotool search --class dropdown)" ]; then + dropdown +fi + +CLASS="dropdown" +ACTIVE_WINDOW="$(xdotool getactivewindow)" +APP_WINDOW="$(xdotool search --onlyvisible --class $CLASS)" + +if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then + xdotool getactivewindow windowminimize +else + wmctrl -xR "$CLASS" +fi + ## List of supported terminals with dropdown class #supported_terminals=( # "wezterm" @@ -139,67 +198,67 @@ # fi #fi -# List of supported terminals with dropdown class -supported_terminals=( - "wezterm" - "kitty" - "alacritty" -) - -# Check if any of the supported terminals with dropdown class are running -for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class dropdown" > /dev/null; then - my_term="$term" - break - fi -done - -# If none of the supported terminals are running, start the first available one -if [ -z "$my_term" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" > /dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ -z "$my_term" ]; then - echo "No supported terminal found." - exit 1 - fi - - # Start the terminal with dropdown class - case "$my_term" in - "wezterm") - wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - "kitty") - kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - "alacritty") - alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - esac -fi - - -# Check if wmctrl is available -if command -v wmctrl > /dev/null 2>&1; then - # Get the window ID of the dropdown terminal - id="$(wmctrl -l | grep "dropdown" | awk '{print $1}')" - - # Toggle the visibility of the dropdown terminal - if [ -n "$id" ]; then - state="$(wmctrl -l -G -p -x | grep "$id" | awk '{print $4}')" - if [ "$state" = "-1" ]; then - # The dropdown window is hidden, so show it - wmctrl -i -r "$id" -b remove,hidden - else - # The dropdown window is visible, so hide it - wmctrl -i -r "$id" -b add,hidden - fi - fi -else - echo "Window manipulation requires wmctrl. Install it and try again." - exit 1 -fi +## List of supported terminals with dropdown class +#supported_terminals=( +# "wezterm" +# "kitty" +# "alacritty" +#) +# +## Check if any of the supported terminals with dropdown class are running +#for term in "${supported_terminals[@]}"; do +# if pgrep -f "$term.*--class dropdown" > /dev/null; then +# my_term="$term" +# break +# fi +#done +# +## If none of the supported terminals are running, start the first available one +#if [ -z "$my_term" ]; then +# for term in "${supported_terminals[@]}"; do +# if command -v "$term" > /dev/null 2>&1; then +# my_term="$term" +# break +# fi +# done +# if [ -z "$my_term" ]; then +# echo "No supported terminal found." +# exit 1 +# fi +# +# # Start the terminal with dropdown class +# case "$my_term" in +# "wezterm") +# wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & +# ;; +# "kitty") +# kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & +# ;; +# "alacritty") +# alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & +# ;; +# esac +#fi +# +# +## Check if wmctrl is available +#if command -v wmctrl > /dev/null 2>&1; then +# # Get the window ID of the dropdown terminal +# id="$(wmctrl -l | grep "dropdown" | awk '{print $1}')" +# +# # Toggle the visibility of the dropdown terminal +# if [ -n "$id" ]; then +# state="$(wmctrl -l -G -p -x | grep "$id" | awk '{print $4}')" +# if [ "$state" = "-1" ]; then +# # The dropdown window is hidden, so show it +# wmctrl -i -r "$id" -b remove,hidden +# else +# # The dropdown window is visible, so hide it +# wmctrl -i -r "$id" -b add,hidden +# fi +# fi +#else +# echo "Window manipulation requires wmctrl. Install it and try again." +# exit 1 +#fi -- cgit v1.2.3 From 7ba53f66cfc305f713717d8d8fc842a4140b6970 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 1 Aug 2023 21:45:16 +0200 Subject: Fix recursion --- dropdown | 112 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/dropdown b/dropdown index 768bda0..a1a8507 100755 --- a/dropdown +++ b/dropdown @@ -6,62 +6,67 @@ # List of supported terminals with dropdown class supported_terminals=( - "wezterm" - "kitty" - "alacritty" + "wezterm" + "kitty" + "alacritty" ) # Check if any of the supported terminals with dropdown class are running for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class dropdown" > /dev/null; then - my_term="$term" - break - fi + if pgrep -f "$term.*--class dropdown" >/dev/null; then + my_term="$term" + break + fi done # If none of the supported terminals are running, start the first available one -if [ -z "$my_term" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" > /dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ -z "$my_term" ]; then - echo "No supported terminal found." - exit 1 - fi +if [ "$my_term" = "" ]; then + for term in "${supported_terminals[@]}"; do + if command -v "$term" >/dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ "$my_term" = "" ]; then + echo "No supported terminal found." + exit 1 + fi - # Start the terminal with dropdown class - case "$my_term" in - "wezterm") - wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - "kitty") - kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - "alacritty") - alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - esac + # Start the terminal with dropdown class + case "$my_term" in + "wezterm") + wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & + ;; + "kitty") + kitty --class dropdown tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & + ;; + "alacritty") + alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & + ;; + esac fi +# Get the window ID of the dropdown terminal +id="$(xdo id -N dropdown)" # Toggle the visibility of the dropdown terminal -#if [ -n "$id" ]; then -if [ -z "$(xdotool search --class dropdown)" ]; then - dropdown +if [ "$id" != "" ]; then + if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then + # xdotool windowminimize "$id" + #else + # wmctrl -xR "$id" + xdo hide "$id" 2>/dev/null + else + # The dropdown window is hidden, so show it + xdo show "$id" + fi fi -CLASS="dropdown" -ACTIVE_WINDOW="$(xdotool getactivewindow)" -APP_WINDOW="$(xdotool search --onlyvisible --class $CLASS)" - -if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then - xdotool getactivewindow windowminimize -else - wmctrl -xR "$CLASS" -fi +#if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then +# xdotool windowminimize "$ACTIVE_WINDOW" +#else +# xdotool windowactivate --sync "$APP_WINDOW" && xdotool windowraise "$APP_WINDOW" +#fi ## List of supported terminals with dropdown class #supported_terminals=( @@ -109,17 +114,17 @@ fi #id="$(xdo id -N dropdown)" # ## Toggle the visibility of the dropdown terminal -#if [ -n "$id" ]; then -# if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; then -# # The dropdown window is visible, so hide it -# dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" -# xdo hide "$id" 2>/dev/null -# else -# # The dropdown window is hidden, so show it -# xdo show "$id" -# # Restore the dimensions of the window -# xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null -# fi +#if [ "$id" != "" ]; then +# if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then +# # The dropdown window is visible, so hide it +# dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" +# xdo hide "$id" 2>/dev/null +# else +# # The dropdown window is hidden, so show it +# xdo show "$id" +# # Restore the dimensions of the window +# xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null +# fi #fi ## Function to get window ID by window class name @@ -261,4 +266,3 @@ fi # echo "Window manipulation requires wmctrl. Install it and try again." # exit 1 #fi - -- cgit v1.2.3 From 978eb44401a37a4b49c2841e7f726761d6425743 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 2 Aug 2023 10:21:50 +0200 Subject: Set window state properties since xprop, etc.. do not seem to get info on the window --- dropdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dropdown b/dropdown index a1a8507..6b0f80e 100755 --- a/dropdown +++ b/dropdown @@ -60,6 +60,9 @@ if [ "$id" != "" ]; then # The dropdown window is hidden, so show it xdo show "$id" fi + # Set properties on the dropdown terminal window + xprop -id "$id" -f _NET_WM_WINDOW_TYPE 32a -set _NET_WM_WINDOW_TYPE _NET_WM_WINDOW_TYPE_NORMAL + xprop -id "$id" -f _NET_WM_STATE 32a -set _NET_WM_STATE _NET_WM_STATE_ABOVE fi #if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then -- cgit v1.2.3 From a5a87990063eaf7028ff827f2d68964d1060f4e2 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 2 Aug 2023 12:15:09 +0200 Subject: GDK_BACKEND=x11 to allow to work in Wayland --- dropdown | 278 +++++++++------------------------------------------------------ 1 file changed, 37 insertions(+), 241 deletions(-) diff --git a/dropdown b/dropdown index 6b0f80e..98de3cc 100755 --- a/dropdown +++ b/dropdown @@ -4,46 +4,49 @@ # Created On: Tue 07 Mar 2023 15:06:47 PM CAT # Project: Agnostic dropdown/scratchpad terminal that works on most window managers +# Set the GDK_BACKEND environment variable to x11 to allow working in Wayland +export GDK_BACKEND=x11 + # List of supported terminals with dropdown class supported_terminals=( - "wezterm" - "kitty" - "alacritty" + "wezterm" + "kitty" + "alacritty" ) # Check if any of the supported terminals with dropdown class are running for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class dropdown" >/dev/null; then - my_term="$term" - break - fi + if pgrep -f "$term.*--class dropdown" > /dev/null; then + my_term="$term" + break + fi done # If none of the supported terminals are running, start the first available one -if [ "$my_term" = "" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" >/dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ "$my_term" = "" ]; then - echo "No supported terminal found." - exit 1 - fi +if [ -z "$my_term" ]; then + for term in "${supported_terminals[@]}"; do + if command -v "$term" > /dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ -z "$my_term" ]; then + echo "No supported terminal found." + exit 1 + fi - # Start the terminal with dropdown class - case "$my_term" in - "wezterm") - wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & - ;; - "kitty") - kitty --class dropdown tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & - ;; - "alacritty") - alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & - ;; - esac + # Start the terminal with dropdown class + case "$my_term" in + "wezterm") + wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + "kitty") + kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + "alacritty") + alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & + ;; + esac fi # Get the window ID of the dropdown terminal @@ -52,220 +55,13 @@ id="$(xdo id -N dropdown)" # Toggle the visibility of the dropdown terminal if [ "$id" != "" ]; then if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then - # xdotool windowminimize "$id" - #else - # wmctrl -xR "$id" + # The dropdown window is visible, so hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" xdo hide "$id" 2>/dev/null else # The dropdown window is hidden, so show it xdo show "$id" + # Restore the dimensions of the window + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null fi - # Set properties on the dropdown terminal window - xprop -id "$id" -f _NET_WM_WINDOW_TYPE 32a -set _NET_WM_WINDOW_TYPE _NET_WM_WINDOW_TYPE_NORMAL - xprop -id "$id" -f _NET_WM_STATE 32a -set _NET_WM_STATE _NET_WM_STATE_ABOVE fi - -#if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then -# xdotool windowminimize "$ACTIVE_WINDOW" -#else -# xdotool windowactivate --sync "$APP_WINDOW" && xdotool windowraise "$APP_WINDOW" -#fi - -## List of supported terminals with dropdown class -#supported_terminals=( -# "wezterm" -# "kitty" -# "alacritty" -#) -# -## Check if any of the supported terminals with dropdown class are running -#for term in "${supported_terminals[@]}"; do -# if pgrep -f "$term.*--class dropdown" > /dev/null; then -# my_term="$term" -# break -# fi -#done -# -## If none of the supported terminals are running, start the first available one -#if [ -z "$my_term" ]; then -# for term in "${supported_terminals[@]}"; do -# if command -v "$term" > /dev/null 2>&1; then -# my_term="$term" -# break -# fi -# done -# if [ -z "$my_term" ]; then -# echo "No supported terminal found." -# exit 1 -# fi -# -# # Start the terminal with dropdown class -# case "$my_term" in -# "wezterm") -# wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & -# ;; -# "kitty") -# kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & -# ;; -# "alacritty") -# alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & -# ;; -# esac -#fi -# -## Get the window ID of the dropdown terminal -#id="$(xdo id -N dropdown)" -# -## Toggle the visibility of the dropdown terminal -#if [ "$id" != "" ]; then -# if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then -# # The dropdown window is visible, so hide it -# dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" -# xdo hide "$id" 2>/dev/null -# else -# # The dropdown window is hidden, so show it -# xdo show "$id" -# # Restore the dimensions of the window -# xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null -# fi -#fi - -## Function to get window ID by window class name -#get_window_id_by_class() { -# local class="$1" -# if command -v ydotool >/dev/null; then -# ydotool search --classname "$class" -# elif command -v xdotool >/dev/null; then -# xdotool search --classname "$class" -# fi -#} -# -## List of supported terminals with dropdown class -#supported_terminals=( -# "wezterm" -# "kitty" -# "alacritty" -#) -# -## Check if any of the supported terminals with dropdown class are running -#for term in "${supported_terminals[@]}"; do -# if pgrep -f "$term.*--class dropdown" >/dev/null; then -# my_term="$term" -# break -# fi -#done -# -## If none of the supported terminals are running, start the first available one -#if [ "$my_term" = "" ]; then -# for term in "${supported_terminals[@]}"; do -# if command -v "$term" >/dev/null 2>&1; then -# my_term="$term" -# break -# fi -# done -# if [ "$my_term" = "" ]; then -# echo "No supported terminal found." -# exit 1 -# fi -# -# # Start the terminal with dropdown class -# case "$my_term" in -# "wezterm") -# wezterm --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & -# ;; -# "kitty") -# kitty --class dropdown tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & -# ;; -# "alacritty") -# alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash >/dev/null 2>&1 & -# ;; -# esac -#fi -# -## Get the window ID of the dropdown terminal using either ydotool or xdotool -#id=$(get_window_id_by_class "dropdown") -# -## Toggle the visibility of the dropdown terminal -#if [ "$id" != "" ]; then -# if command -v ydotool >/dev/null; then -# if ydotool windowvisible "$id"; then -# # The dropdown window is visible, so hide it -# ydotool windowunmap "$id" -# else -# # The dropdown window is hidden, so show it -# ydotool windowmap "$id" -# fi -# elif command -v xdotool >/dev/null; then -# if xdotool getwindowfocus | grep -q "$id"; then -# # The dropdown window is visible, so hide it -# xdotool windowunmap "$id" -# else -# # The dropdown window is hidden, so show it -# xdotool windowmap "$id" -# fi -# fi -#fi - -## List of supported terminals with dropdown class -#supported_terminals=( -# "wezterm" -# "kitty" -# "alacritty" -#) -# -## Check if any of the supported terminals with dropdown class are running -#for term in "${supported_terminals[@]}"; do -# if pgrep -f "$term.*--class dropdown" > /dev/null; then -# my_term="$term" -# break -# fi -#done -# -## If none of the supported terminals are running, start the first available one -#if [ -z "$my_term" ]; then -# for term in "${supported_terminals[@]}"; do -# if command -v "$term" > /dev/null 2>&1; then -# my_term="$term" -# break -# fi -# done -# if [ -z "$my_term" ]; then -# echo "No supported terminal found." -# exit 1 -# fi -# -# # Start the terminal with dropdown class -# case "$my_term" in -# "wezterm") -# wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & -# ;; -# "kitty") -# kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & -# ;; -# "alacritty") -# alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & -# ;; -# esac -#fi -# -# -## Check if wmctrl is available -#if command -v wmctrl > /dev/null 2>&1; then -# # Get the window ID of the dropdown terminal -# id="$(wmctrl -l | grep "dropdown" | awk '{print $1}')" -# -# # Toggle the visibility of the dropdown terminal -# if [ -n "$id" ]; then -# state="$(wmctrl -l -G -p -x | grep "$id" | awk '{print $4}')" -# if [ "$state" = "-1" ]; then -# # The dropdown window is hidden, so show it -# wmctrl -i -r "$id" -b remove,hidden -# else -# # The dropdown window is visible, so hide it -# wmctrl -i -r "$id" -b add,hidden -# fi -# fi -#else -# echo "Window manipulation requires wmctrl. Install it and try again." -# exit 1 -#fi -- cgit v1.2.3 From bc71ccace62dd4ad6495004a2487a08b463580d6 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 2 Aug 2023 12:36:44 +0200 Subject: Combind old script dropdown into here --- scratchpad | 91 ++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/scratchpad b/scratchpad index 2192236..1b3dfeb 100755 --- a/scratchpad +++ b/scratchpad @@ -1,41 +1,68 @@ -#!/usr/bin/bash +#!/bin/bash # Created By: srdusr -# Created On: Wed 18 Jan 2023 11:15:22 PM CAT -# Project: bspwm scratchpad with tmux session - -id=$(xdo id -n scratchpad); -if [ -z "$id" ]; then - wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash > /dev/null 2>&1 & -else - bspc node "$id" -g hidden -f -fi - -#- - - - - - - - - - - +# Created On: Tue 07 Mar 2023 15:06:47 PM CAT +# Project: Agnostic scratchpad/dropdown terminal that works on most window managers -### Other Window Managers +# Set the GDK_BACKEND and QT_QPA_PLATFORM environment variables to x11 to allow working in Wayland +export GDK_BACKEND=x11 +export QT_QPA_PLATFORM=xcb -#id=$(xdotool search --class scratchpad); -#if [ -z "$id" ]; then -# wezterm start --class scratchpad -e tmux new-session -A -s scratch -e bash > /dev/null 2>&1 & -#else -# if [ ! -f /tmp/scratchpad ]; then -# touch /tmp/scratchpad && xdo hide "$id" -# elif [ -f /tmp/scratchpad ]; then -# rm /tmp/scratchpad && xdo show "$id" -# fi -#fi +# List of supported terminals with dropdown class +supported_terminals=( + "wezterm" + "kitty" + "alacritty" +) -#- - - - - - - - - - +# Check if any of the supported terminals with scratchpad class are running +for term in "${supported_terminals[@]}"; do + if pgrep -f "$term.*--class scratchpad" >/dev/null; then + my_term="$term" + break + fi +done +# If none of the supported terminals are running, start the first available one +if [ "$my_term" = "" ]; then + for term in "${supported_terminals[@]}"; do + if command -v "$term" >/dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ "$my_term" = "" ]; then + echo "No supported terminal found." + exit 1 + fi -### Alacritty alternative - -#if id="$(xdo id -N scratch)" -# then bspc node "$id" -g hidden -f -# else alacritty --class scratch,scratchpad -e tmux new-session -A -s scratch -e bash > /dev/null 2>&1 & -#fi + # Start the terminal with scratchpad class + case "$my_term" in + "wezterm") + wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "kitty") + kitty --class scratchpad tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "alacritty") + alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + esac +fi -#- - - - - - - - - - +# Get the window ID of the scratchpad terminal +id="$(xdo id -N scratchpad)" +# Toggle the visibility of the scratchpad terminal +if [ "$id" != "" ]; then + if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then + # The scratchpad window is visible, so hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" + xdo hide "$id" 2>/dev/null + else + # The scratchpad window is hidden, so show it + xdo show "$id" + # Restore the dimensions of the window + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null + fi +fi -- cgit v1.2.3 From 61592e6d39eb84ef57621229463566a642285b4d Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 2 Aug 2023 12:37:39 +0200 Subject: Moved dropdown into scratchpad script --- dropdown | 67 ---------------------------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100755 dropdown diff --git a/dropdown b/dropdown deleted file mode 100755 index 98de3cc..0000000 --- a/dropdown +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -# Created By: srdusr -# Created On: Tue 07 Mar 2023 15:06:47 PM CAT -# Project: Agnostic dropdown/scratchpad terminal that works on most window managers - -# Set the GDK_BACKEND environment variable to x11 to allow working in Wayland -export GDK_BACKEND=x11 - -# List of supported terminals with dropdown class -supported_terminals=( - "wezterm" - "kitty" - "alacritty" -) - -# Check if any of the supported terminals with dropdown class are running -for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class dropdown" > /dev/null; then - my_term="$term" - break - fi -done - -# If none of the supported terminals are running, start the first available one -if [ -z "$my_term" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" > /dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ -z "$my_term" ]; then - echo "No supported terminal found." - exit 1 - fi - - # Start the terminal with dropdown class - case "$my_term" in - "wezterm") - wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - "kitty") - kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - "alacritty") - alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 & - ;; - esac -fi - -# Get the window ID of the dropdown terminal -id="$(xdo id -N dropdown)" - -# Toggle the visibility of the dropdown terminal -if [ "$id" != "" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then - # The dropdown window is visible, so hide it - dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" - xdo hide "$id" 2>/dev/null - else - # The dropdown window is hidden, so show it - xdo show "$id" - # Restore the dimensions of the window - xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null - fi -fi -- cgit v1.2.3 From 9556d15284ced4920dde65f75956f139b91cc5d6 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 2 Aug 2023 16:18:26 +0200 Subject: Initial commit --- qemu-helper.sh | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100755 qemu-helper.sh diff --git a/qemu-helper.sh b/qemu-helper.sh new file mode 100755 index 0000000..0d38aba --- /dev/null +++ b/qemu-helper.sh @@ -0,0 +1,172 @@ +#!/bin/bash + +# Created By: srdusr +# Created On: Wed 02 Aug 2023 16:16:21 PM CAT +# Project: QEMU setup/opener helper wrapper script + +# Set global variables for VM parameters +ram_size="4G" + +# Function to prompt user for VM parameters +function get_vm_parameters() { + read -p "Enter VM name (default: vm): " vm_name + vm_name=${vm_name:-vm} + + # Set the default ISO file path to ~/machines/images + default_iso_path="$HOME/machines/images" + + # Generate completions for ISO and IMG files in the images directory + COMPREPLY=() + local files=$(compgen -G "$default_iso_path/*.{iso,img}" -o plusdirs) + for file in $files; do + COMPREPLY+=("$file") + done + + # Use read with -i and -e options for tab-completion + read -ep "Enter ISO file path (default: $default_iso_path): " -i "$default_iso_path" iso_path + + # Manually expand the ~ to the user's home directory + iso_path=$(eval echo "$iso_path") + + # Validate the user input + while [ ! -f "$iso_path" ]; do + read -ep "Invalid file path. Enter a valid ISO file path: " iso_path + done + + # Check if the selected file is an IMG file + if [[ "$iso_path" == *.img ]]; then + guest_os="windows" + else + guest_os="linux" + fi + + # Show available disk space before asking for disk image size + echo "Available disk space:" + df -h "$vm_images_path" + + read -p "Enter disk image size in GB (default: 10G): " disk_size + disk_size=${disk_size:-10G} + + read -p "Enter RAM size in GB (default: 4G): " ram_size + ram_size=${ram_size:-4G} + + # Check if the RAM size is in the correct format (e.g., "4G") + while ! [[ $ram_size =~ ^[0-9]+[kKmMgGtTpPeE]$ ]]; do + read -p "Invalid RAM size format. Enter RAM size in GB (e.g., 4G): " ram_size + done + + read -p "Enter number of CPU cores (default: 2): " cpu_cores + cpu_cores=${cpu_cores:-2} +} + + +# Function to list available VMs +function list_vms() { + echo "Available VMs:" + for vm_file in "$vm_images_path"/*.qcow2; do + vm=$(basename "$vm_file" .qcow2) + echo " - $vm" + done +} + +# Function to list available ISO and IMG files in the images directory +function list_iso_img_files() { + echo "Available ISO and IMG files in $iso_images_path:" + iso_img_files=() + while IFS= read -r -d $'\0' file; do + iso_img_files+=("$file") + done < <(find "$iso_images_path" -type f \( -iname \*.iso -o -iname \*.img \) -print0) + + for ((i = 0; i < ${#iso_img_files[@]}; i++)); do + echo " $((i + 1)). ${iso_img_files[i]##*/}" + done +} + +# Function to check if VM is already running +function is_vm_running() { + vm_name=$1 + if ps aux | grep -v grep | grep -q "[q]emu-system-x86_64.*$vm_name"; then + return 0 + else + return 1 + fi +} + +# Function to start VM +function start_vm() { + vm_name=$1 + is_vm_running "$vm_name" + if [ $? -eq 0 ]; then + echo "VM '$vm_name' is already running." + return + fi + + # VM parameters + qemu_cmd="qemu-system-x86_64 -enable-kvm -machine type=q35 -m $ram_size -cpu host -smp 2 -vga virtio" + qemu_cmd+=" -device qemu-xhci -device usb-tablet -device usb-kbd -device virtio-net,netdev=user0 -netdev user,id=user0,hostfwd=tcp::5555-:22" + qemu_cmd+=" -cdrom \"$iso_path\" -drive file=\"$vm_images_path/$vm_name.qcow2\",index=0,media=disk,if=virtio" + + if [[ $guest_os == "windows" ]]; then + qemu_cmd+=" -drive file=\"$iso_images_path/virtio-win.iso\",index=3,media=cdrom" + fi + + qemu_cmd+=" -boot menu=on" + qemu_cmd+=" -net nic -net user,hostname=$vm_name -name \"$vm_name\"" + + echo "Starting VM: $vm_name" + eval "$qemu_cmd" +} + +# Main script starts here +vm_images_path="$HOME/machines/vm" +iso_images_path="$HOME/machines/images" + +# Check if directories exist +mkdir -p "$vm_images_path" +mkdir -p "$iso_images_path" + +# List available VMs +list_vms + +# List available ISO and IMG files in the images directory +list_iso_img_files + +# Ask the user if they want to use an existing VM or create a new one +read -p "Do you want to use an existing VM? (y/n): " use_existing_vm +if [[ $use_existing_vm =~ ^[Yy]$ ]]; then + read -p "Enter the name of the existing VM: " existing_vm_name + while [ ! -f "$vm_images_path/$existing_vm_name.qcow2" ]; do + echo "VM '$existing_vm_name' does not exist." + read -p "Enter a valid existing VM name: " existing_vm_name + done + vm_name=$existing_vm_name +else + # Prompt user for VM parameters + get_vm_parameters + + # Check if VM already exists + if [ -f "$vm_images_path/$vm_name.qcow2" ]; then + read -p "VM '$vm_name' already exists. Do you want to start it? (y/n): " start_vm_choice + if [[ $start_vm_choice =~ ^[Yy]$ ]]; then + start_vm "$vm_name" + exit 0 + fi + else + # Create new VM + echo "Creating new VM: $vm_name" + qemu-img create -f qcow2 "$vm_images_path/$vm_name.qcow2" "$disk_size" + start_vm "$vm_name" + exit 0 + fi +fi + +# If an existing VM is selected, ask if the user wants to modify its parameters +read -p "Do you want to modify the VM parameters? (y/n): " modify_vm_params +if [[ $modify_vm_params =~ ^[Yy]$ ]]; then + get_vm_parameters +fi + +# Start the VM +start_vm "$vm_name" + +echo "Script execution completed." -- cgit v1.2.3 From adcbeb8beac922537673e8a7c4f0553b8f2b9997 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 2 Aug 2023 16:35:47 +0200 Subject: Removed termy --- get_zle_keymap_select.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 get_zle_keymap_select.sh diff --git a/get_zle_keymap_select.sh b/get_zle_keymap_select.sh new file mode 100755 index 0000000..1e2eaf4 --- /dev/null +++ b/get_zle_keymap_select.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Get the value of the zle-keymap-select variable +value=$(print -v zle-keymap-select) + +# Specify the file path to save the value +file_path="~/file.txt" + +# Write the value to the file +echo "$value" > "$file_path" + +# Optionally, you can also print the value to the console +echo "The value of zle-keymap-select is: $value" -- cgit v1.2.3 From a3b9018f0a17f8473941a9d0f8323161f93903c3 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 6 Aug 2023 22:54:27 +0200 Subject: Removed script "termy" --- termy | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 termy diff --git a/termy b/termy deleted file mode 100644 index c207800..0000000 --- a/termy +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -# if app is not open then launch it -- remove this if you don't want your -# shortcut to launch the application if it hasn't been launched yet -if [ -z "$(xdotool search --class konsole)" ]; then - konsole -fi - -# get current focused window and visible konsole window -CLASS="konsole" -ACTIVE_WINDOW="$(xdotool getactivewindow)" -APP_WINDOW="$(xdotool search --onlyvisible --class $CLASS)" - -# if focused, minimize and hide the konsole, otherwise bring konsole to current desktop and open -if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then - xdotool getactivewindow windowminimize -else - wmctrl -xR "$CLASS" -fi - -- cgit v1.2.3 From 57629466749a7848ffffab2da9129a3137e67857 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 6 Aug 2023 22:55:05 +0200 Subject: Add install.sh --- install.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..b811355 --- /dev/null +++ b/install.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [[ $EUID -eq 0 ]]; then + echo "This script must not be run as root" + exit 1 +fi + +# Install system packages +packages=( + "ripgrep" + "xclip" + "ctags" +) + +for package in "${packages[@]}"; do + if ! pacman -Qi "$package" > /dev/null 2>&1; then + sudo pacman -S --noconfirm "$package" + fi +done -- cgit v1.2.3 From a69966aaa6221ff0c966a360cb942a608956ee59 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 6 Aug 2023 22:56:04 +0200 Subject: Add dotfiles.sh --- dotfiles.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 dotfiles.sh diff --git a/dotfiles.sh b/dotfiles.sh new file mode 100755 index 0000000..b231367 --- /dev/null +++ b/dotfiles.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Set the bare dotfiles repo directory +dotfiles_dir="$HOME/.cfg" + +# Set the home directory +home_dir="$HOME" + +# Exclude the .cfg directory and any other files/directories you want to ignore +exclude_list=(".cfg") + +# Change to the home directory +cd "$home_dir" + +# Get a list of all dotfiles in the repository +files=$(find "$dotfiles_dir" -maxdepth 1 -type f -not -name ".*" -not -name "${exclude_list[*]}" -printf "%f\n") + +# Link each file to its corresponding location in $HOME +for file in $files; do + ln -sf "$dotfiles_dir/$file" "$home_dir/.$file" +done + +# Get a list of all dot directories in the repository +dirs=$(find "$dotfiles_dir" -maxdepth 1 -type d -not -path "$dotfiles_dir" -not -name ".*" -not -name "${exclude_list[*]}" -printf "%f\n") + +# Link each directory to its corresponding location in $HOME +for dir in $dirs; do + ln -sf "$dotfiles_dir/$dir" "$home_dir/.$dir" +done + +# Remove any symlinks that are no longer present in the repo +while IFS= read -r -d '' link; do + if [[ ! -e "$link" ]]; then + rm "$link" + fi +done < <(find "$home_dir" -maxdepth 1 -type l -name ".*" -not -name ".cfg" -print0) + -- cgit v1.2.3 From c862355da6e7d3053bb7869e59aff8616abeed1a Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 6 Aug 2023 22:56:46 +0200 Subject: Add check-updates.sh --- check-updates.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 check-updates.sh diff --git a/check-updates.sh b/check-updates.sh new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 692db3d7b9b80c1849b283738f6a2fe61ea0cdd2 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 6 Aug 2023 22:57:57 +0200 Subject: Download winget --- win-nvim.bat | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/win-nvim.bat b/win-nvim.bat index 3439ffb..c99374d 100644 --- a/win-nvim.bat +++ b/win-nvim.bat @@ -29,3 +29,9 @@ if not exist "%localPacker%\." ( REM Run the script by using this command in the same existing directory: win-nvim.bat +@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://aka.ms/install-winget'))" +iex ((new-object net.webclient).DownloadString('https://aka.ms/install-winget')) +curl -o winget-cli.appxbundle https://aka.ms/winget-cli-appxbundle + +powershell Add-AppxPackage -Path "winget-cli.appxbundle" + -- cgit v1.2.3