Compare commits

...

3 commits

Author SHA1 Message Date
f4f315df42
tmux <prefix>-b to change git branches fast
Uses gitB function from common.sh

Also added confirmation to delete workspace
2022-01-23 15:31:34 +02:00
cbe5e8442f
add_workspace now checks if there is a WS for pwd and asks if to override 2022-01-23 12:28:42 +02:00
fe3b4dd7ee
workspace manager: when adding same name ask to override 2022-01-23 10:52:04 +02:00
4 changed files with 58 additions and 5 deletions

View file

@ -41,6 +41,10 @@ export EDITOR=vim;
function gitB() { function gitB() {
if [ -d ./.git ]; then if [ -d ./.git ]; then
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ $(git branch | wc -l) -lt 2 ]; then
echo "⚠️ Only ${CURRENT_BRANCH} exists."
return 1
fi
BRANCH=$(git branch -l |sed '/\*/d'| fzf --reverse --header="Current Branch: ${CURRENT_BRANCH}. Select Branch to checkout") BRANCH=$(git branch -l |sed '/\*/d'| fzf --reverse --header="Current Branch: ${CURRENT_BRANCH}. Select Branch to checkout")
if [ -z ${BRANCH} ]; then if [ -z ${BRANCH} ]; then
echo Canceled echo Canceled
@ -202,7 +206,3 @@ function grid() {
return 0 return 0
} }
function add_workspace() {
~/.shellconfig/workspaces/add_workspace.sh ${1} || return 1
}

View file

@ -2,9 +2,32 @@
JSON_PATH=~/.shellconfig/workspaces/workspaces.json JSON_PATH=~/.shellconfig/workspaces/workspaces.json
function yes_no_question() {
QUESTION=$1
RESPONSE=$(cat <<EOF | fzf --reverse --header "${QUESTION}"
No
Yes
EOF
)
echo $RESPONSE
}
NAME=${1:-} NAME=${1:-}
# check if folder already saved as a workspace
EXISTING_WSP=$(cat $JSON_PATH | jq -r --arg pwd $(pwd) 'to_entries[] | select(.value.dir == $pwd)')
if [ ! -z "$EXISTING_WSP" ]; then
WSP_NAME=$(echo "$EXISTING_WSP" | jq -r --arg pwd $(pwd) '.key')
RESPONSE=$(yes_no_question "⚠️ There is already a workspace named '${WSP_NAME}' for this folder. Would you like to override?")
if [[ "$RESPONSE" != "Yes" ]]; then
echo Canceled
exit
fi
NAME=$WSP_NAME
fi
if [ -z "$NAME" ]; then if [ -z "$NAME" ]; then
read -p "🖥 Please give this workspace a name: " NAME read -p "🖥 Please give this workspace a name: " NAME
fi fi
@ -14,6 +37,15 @@ if [ -z "$NAME" ]; then
exit 1 exit 1
fi fi
# Check if workspace already exists
if [ -z "$EXISTING_WSP" ] && [ $(cat $JSON_PATH | jq 'keys' | grep "${NAME}") ]; then
OVERRIDE=$(yes_no_question "a Worspace with name '${NAME}' already exists. Override?")
if [[ "$OVERRIDE" == "No" ]]; then
echo Canceled
exit
fi
fi
CURRENT_DIR=$(pwd) CURRENT_DIR=$(pwd)
LAYOUT=$(cat <<EOF | fzf --reverse --header "Select a layout for ${NAME}" LAYOUT=$(cat <<EOF | fzf --reverse --header "Select a layout for ${NAME}"

View file

@ -2,6 +2,17 @@
JSON_PATH=~/.shellconfig/workspaces/workspaces.json JSON_PATH=~/.shellconfig/workspaces/workspaces.json
function yes_no_question() {
QUESTION=$1
RESPONSE=$(cat <<EOF | fzf --reverse --header "${QUESTION}"
No
Yes
EOF
)
echo $RESPONSE
}
WSP=$(cat ${JSON_PATH} \ WSP=$(cat ${JSON_PATH} \
| jq -r 'keys[]' \ | jq -r 'keys[]' \
| fzf --reverse --header "Select a Workspace to DELETE" | fzf --reverse --header "Select a Workspace to DELETE"
@ -12,6 +23,13 @@ if [ -z $WSP ]; then
exit 1 exit 1
fi fi
RESPONSE=$(yes_no_question "❓ Are you sure you want to delete ${WSP}?")
if [ "$RESPONSE" == "No" ]; then
echo "Aborted"
exit
fi
echo $(cat ${JSON_PATH} | jq --arg WSP "$WSP" 'del(.[$WSP])') > ${JSON_PATH} echo $(cat ${JSON_PATH} | jq --arg WSP "$WSP" 'del(.[$WSP])') > ${JSON_PATH}
echo "⚠️ '${WSP}' Was removed from your workspaces" echo "⚠️ '${WSP}' Was removed from your workspaces"

View file

@ -41,11 +41,14 @@ bind-key i run-shell "tmux neww -n '🏳️ CHEATER\! 😎' ~/.shellconfig/cheat
bind-key o run-shell "tmux neww -n '🖥Workspace Manager' ~/.shellconfig/workspaces/open_workspace.sh" bind-key o run-shell "tmux neww -n '🖥Workspace Manager' ~/.shellconfig/workspaces/open_workspace.sh"
# Add/Save Workspace # Add/Save Workspace
bind-key a send-keys "add_workspace" C-m bind-key a run-shell "tmux neww -n '🖥Workspace Manager' 'cd #{pane_current_path} && ~/.shellconfig/workspaces/add_workspace.sh'"
# Delete (x) Workspace # Delete (x) Workspace
bind-key x run-shell "tmux neww -n '🖥Workspace Manager' ~/.shellconfig/workspaces/delete_workspace.sh" bind-key x run-shell "tmux neww -n '🖥Workspace Manager' ~/.shellconfig/workspaces/delete_workspace.sh"
# Change git branches fast <prefix>-b
bind-key b send-keys "gitB" C-m
############################ ############################
# Themes # Themes
########################### ###########################