Merge branch 'cli-workspace-manager' into 'main'

Simple tmux based workspace manager

See merge request sagidayan/linux-config!11
This commit is contained in:
Sagi Dayan 2022-01-22 15:37:23 +00:00
commit ba74923f3a
7 changed files with 141 additions and 2 deletions

View file

@ -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
}

View file

@ -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 <<EOF | fzf --reverse --header "Select a layout for ${NAME}"
ide
grid
layout "2 1"
layout "1 2"
EOF
)
if [ -z "$LAYOUT" ]; then
echo "Invalid layout"
exit 1
fi
echo $(cat ${JSON_PATH} \
| jq --arg NAME "$NAME" --arg LAYOUT "$LAYOUT" --arg CURRENT_DIR "$CURRENT_DIR" '. + {($NAME):{layout: $LAYOUT, dir: $CURRENT_DIR}}') > ${JSON_PATH}
echo "✅ Added ${NAME}"

View file

@ -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"

View file

@ -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

View file

@ -0,0 +1 @@
{}

View file

@ -36,6 +36,16 @@ bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."
# Lookup the cheat sheet <prefix>-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
###########################

View file

@ -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