mirror of
https://gitlab.com/sagidayan/linux-config.git
synced 2024-11-24 00:05:25 +00:00
Simple tmux based workspace manager
- tmux key-bindings for save/open/delete workspace - each workspace has a layout based on common.sh functions such as `ide` `grid` and `layout`
This commit is contained in:
parent
736e2f8eb8
commit
79ab87fa07
7 changed files with 141 additions and 2 deletions
|
@ -40,11 +40,14 @@ export EDITOR=vim;
|
||||||
|
|
||||||
function gitB() {
|
function gitB() {
|
||||||
if [ -d ./.git ]; then
|
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
|
if [ -z ${BRANCH} ]; then
|
||||||
echo Canceled
|
echo Canceled
|
||||||
else
|
else
|
||||||
git ck ${BRANCH}
|
BRANCH=$(echo $BRANCH | xargs)
|
||||||
|
echo "Swiching to ${BRANCH}"
|
||||||
|
git ck "${BRANCH}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "[ERROR]: Not in a git repository"
|
echo "[ERROR]: Not in a git repository"
|
||||||
|
@ -199,3 +202,7 @@ function grid() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function add_workspace() {
|
||||||
|
~/.shellconfig/workspaces/add_workspace.sh ${1} || return 1
|
||||||
|
}
|
||||||
|
|
33
files/dotfiles/shellconfig/workspaces/add_workspace.sh
Executable file
33
files/dotfiles/shellconfig/workspaces/add_workspace.sh
Executable 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}"
|
||||||
|
|
17
files/dotfiles/shellconfig/workspaces/delete_workspace.sh
Executable file
17
files/dotfiles/shellconfig/workspaces/delete_workspace.sh
Executable 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"
|
37
files/dotfiles/shellconfig/workspaces/open_workspace.sh
Executable file
37
files/dotfiles/shellconfig/workspaces/open_workspace.sh
Executable 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
|
||||||
|
|
||||||
|
|
||||||
|
|
1
files/dotfiles/shellconfig/workspaces/workspaces.json
Normal file
1
files/dotfiles/shellconfig/workspaces/workspaces.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -36,6 +36,16 @@ bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."
|
||||||
|
|
||||||
# Lookup the cheat sheet <prefix>-i
|
# Lookup the cheat sheet <prefix>-i
|
||||||
bind-key i run-shell "tmux neww -n '🏳️ CHEATER\! 😎' ~/.shellconfig/cheat.sh"
|
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
|
# Themes
|
||||||
###########################
|
###########################
|
||||||
|
|
|
@ -131,3 +131,37 @@
|
||||||
- name: Install modern UNIX tools
|
- name: Install modern UNIX tools
|
||||||
include_role:
|
include_role:
|
||||||
name: modern_unix_tools
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue