diff --git a/files/dotfiles/shellconfig/common.sh b/files/dotfiles/shellconfig/common.sh index 1e254e1..faf3b16 100644 --- a/files/dotfiles/shellconfig/common.sh +++ b/files/dotfiles/shellconfig/common.sh @@ -40,11 +40,14 @@ export EDITOR=vim; function gitB() { if [ -d ./.git ]; then - BRANCH=$(git branch -l | fzf --reverse --header="Select Branch to checkout") + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + BRANCH=$(git branch -l |sed '/\*/d'| fzf --reverse --header="Current Branch: ${CURRENT_BRANCH}. Select Branch to checkout") if [ -z ${BRANCH} ]; then echo Canceled else - git ck ${BRANCH} + BRANCH=$(echo $BRANCH | xargs) + echo "Swiching to ${BRANCH}" + git ck "${BRANCH}" fi else echo "[ERROR]: Not in a git repository" @@ -199,3 +202,7 @@ function grid() { return 0 } + +function add_workspace() { + ~/.shellconfig/workspaces/add_workspace.sh ${1} || return 1 +} diff --git a/files/dotfiles/shellconfig/workspaces/add_workspace.sh b/files/dotfiles/shellconfig/workspaces/add_workspace.sh new file mode 100755 index 0000000..72c0e69 --- /dev/null +++ b/files/dotfiles/shellconfig/workspaces/add_workspace.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +JSON_PATH=~/.shellconfig/workspaces/workspaces.json + + + +NAME=${1:-} +if [ -z "$NAME" ]; then + read -p "🖥 Please give this workspace a name: " NAME +fi + +if [ -z "$NAME" ]; then + echo "Error: Invalid workspace name" + exit 1 +fi + +CURRENT_DIR=$(pwd) + +LAYOUT=$(cat < ${JSON_PATH} +echo "✅ Added ${NAME}" + diff --git a/files/dotfiles/shellconfig/workspaces/delete_workspace.sh b/files/dotfiles/shellconfig/workspaces/delete_workspace.sh new file mode 100755 index 0000000..fa21fc5 --- /dev/null +++ b/files/dotfiles/shellconfig/workspaces/delete_workspace.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +JSON_PATH=~/.shellconfig/workspaces/workspaces.json + +WSP=$(cat ${JSON_PATH} \ + | jq -r 'keys[]' \ + | fzf --reverse --header "Select a Workspace to DELETE" +) + +if [ -z $WSP ]; then + echo "Aborted" + exit 1 +fi + +echo $(cat ${JSON_PATH} | jq --arg WSP "$WSP" 'del(.[$WSP])') > ${JSON_PATH} + +echo "⚠️ '${WSP}' Was removed from your workspaces" diff --git a/files/dotfiles/shellconfig/workspaces/open_workspace.sh b/files/dotfiles/shellconfig/workspaces/open_workspace.sh new file mode 100755 index 0000000..a1d8fb9 --- /dev/null +++ b/files/dotfiles/shellconfig/workspaces/open_workspace.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +JSON_PATH=~/.shellconfig/workspaces/workspaces.json + +WSP=$(cat ${JSON_PATH} \ + | jq -r 'keys[]' \ + | fzf --reverse --header "Select a Project to open" +) + +if [ -z $WSP ]; then + echo "Aborted" + exit 1 +fi + +DIR=$(cat ${JSON_PATH} \ + | jq -r --arg WSP "${WSP}" '.[$WSP]|.["dir"]' \ + | tr -d '\r' +) +LAYOUT=$(cat ${JSON_PATH} \ + | jq -r --arg WSP "${WSP}" '.[$WSP]|.["layout"]' \ + | tr -d '\r' +) + +cd "$DIR" + +LAYOUT_ARGS=$(echo $LAYOUT | grep -oP "(?<=layout ).*(?)") +echo $LAYOUT_ARGS + +tmux neww +if [ ! -z $IS_LAYOUT ]; then + tmux send-keys "layout '${LAYOUT_ARGS}' '${WPS}'" +else + tmux send-keys "${LAYOUT} '${WSP}'" C-m +fi + + + diff --git a/files/dotfiles/shellconfig/workspaces/workspaces.json b/files/dotfiles/shellconfig/workspaces/workspaces.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/files/dotfiles/shellconfig/workspaces/workspaces.json @@ -0,0 +1 @@ +{} diff --git a/files/dotfiles/tmux.conf b/files/dotfiles/tmux.conf index c39a811..a3fc9c0 100644 --- a/files/dotfiles/tmux.conf +++ b/files/dotfiles/tmux.conf @@ -36,6 +36,16 @@ bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded." # Lookup the cheat sheet -i bind-key i run-shell "tmux neww -n '🏳️ CHEATER\! 😎' ~/.shellconfig/cheat.sh" + +# Open Workspace +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 + +# Delete (x) Workspace +bind-key x run-shell "tmux neww -n '🖥Workspace Manager' ~/.shellconfig/workspaces/delete_workspace.sh" + ############################ # Themes ########################### diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index da26d4c..8a831ec 100644 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -131,3 +131,37 @@ - name: Install modern UNIX tools include_role: name: modern_unix_tools + +- name: Copy workspaces files + block: + - name: Make sure directory is there + file: + path: ~/.shellconfig/workspaces + state: directory + mode: '0755' + - name: Copy json + copy: + src: dotfiles/shellconfig/workspaces/workspaces.json + dest: ~/.shellconfig/workspaces/workspaces.json + force: no + mode: preserve + - name: Copy add script + copy: + src: dotfiles/shellconfig/workspaces/add_workspace.sh + dest: ~/.shellconfig/workspaces/add_workspace.sh + force: yes + mode: preserve + - name: Copy open script + copy: + src: dotfiles/shellconfig/workspaces/open_workspace.sh + dest: ~/.shellconfig/workspaces/open_workspace.sh + force: yes + mode: preserve + - name: Copy delete script + copy: + src: dotfiles/shellconfig/workspaces/delete_workspace.sh + dest: ~/.shellconfig/workspaces/delete_workspace.sh + force: yes + mode: preserve + +