mirror of
https://gitlab.com/sagidayan/linux-config.git
synced 2024-12-23 06:29:53 +00:00
Compare commits
3 commits
ba74923f3a
...
f4f315df42
Author | SHA1 | Date | |
---|---|---|---|
f4f315df42 | |||
cbe5e8442f | |||
fe3b4dd7ee |
4 changed files with 58 additions and 5 deletions
|
@ -41,6 +41,10 @@ export EDITOR=vim;
|
|||
function gitB() {
|
||||
if [ -d ./.git ]; then
|
||||
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")
|
||||
if [ -z ${BRANCH} ]; then
|
||||
echo Canceled
|
||||
|
@ -202,7 +206,3 @@ function grid() {
|
|||
return 0
|
||||
}
|
||||
|
||||
|
||||
function add_workspace() {
|
||||
~/.shellconfig/workspaces/add_workspace.sh ${1} || return 1
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -14,6 +37,15 @@ if [ -z "$NAME" ]; then
|
|||
exit 1
|
||||
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)
|
||||
|
||||
LAYOUT=$(cat <<EOF | fzf --reverse --header "Select a layout for ${NAME}"
|
||||
|
|
|
@ -2,6 +2,17 @@
|
|||
|
||||
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} \
|
||||
| jq -r 'keys[]' \
|
||||
| fzf --reverse --header "Select a Workspace to DELETE"
|
||||
|
@ -12,6 +23,13 @@ if [ -z $WSP ]; then
|
|||
exit 1
|
||||
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 "⚠️ '${WSP}' Was removed from your workspaces"
|
||||
|
|
|
@ -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"
|
||||
|
||||
# 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
|
||||
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
|
||||
###########################
|
||||
|
|
Loading…
Reference in a new issue