mirror of
https://gitlab.com/sagidayan/linux-config.git
synced 2024-12-22 05:59:53 +00:00
add_workspace now checks if there is a WS for pwd and asks if to override
This commit is contained in:
parent
fe3b4dd7ee
commit
cbe5e8442f
1 changed files with 25 additions and 6 deletions
|
@ -2,9 +2,32 @@
|
|||
|
||||
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:-}
|
||||
|
||||
# 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
|
||||
read -p "🖥 Please give this workspace a name: " NAME
|
||||
fi
|
||||
|
@ -15,12 +38,8 @@ if [ -z "$NAME" ]; then
|
|||
fi
|
||||
|
||||
# Check if workspace already exists
|
||||
if [ $(cat $JSON_PATH | jq 'keys' | grep "${NAME}") ]; then
|
||||
OVERRIDE=$(cat <<EOF | fzf --reverse --header "a Worspace with name '${NAME}' already exists. Override?"
|
||||
No
|
||||
Yes
|
||||
EOF
|
||||
)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue