Skip to content

Commit

Permalink
Major refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
sei40kr committed Jul 22, 2021
1 parent 4fca3b4 commit 2079e5d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
23 changes: 15 additions & 8 deletions per-project-session.tmux
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
#!/usr/bin/env bash
# -*- mode: sh -*-
# -*- mode: sh; sh-shell: bash -*-

basedir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# shellcheck source=lib/tmux.bash
. "${basedir}/lib/tmux.bash"
default_key_binding_switch="g"
tmux_option_switch="@per-project-session-switch"

main() {
local switch_key
switch_key="$(tmux_get_option "@per-project-session-switch" 'g')"
# shellcheck source=scripts/helpers.sh
. "${CURRENT_DIR}/scripts/helpers.sh"

set_new_session_binding() {
local key
key="$(get_tmux_option "$tmux_option_switch" "$default_key_binding_switch")"

tmux bind-key "$switch_key" run-shell -b "${basedir}/libexec/switch-session"
tmux bind-key "$key" run-shell -b "${CURRENT_DIR}/scripts/switch_session.sh"
}

main() {
set_new_session_binding
}

main
2 changes: 1 addition & 1 deletion lib/tmux.bash → scripts/helpers.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tmux_get_option() {
get_tmux_option() {
local option
local default
local value
Expand Down
27 changes: 17 additions & 10 deletions libexec/switch-session → scripts/switch_session.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#!/usr/bin/env bash

# goto-session.bash
# author: Seong Yong-ju <sei40kr@gmail.com>
# -*- mode: sh; sh-shell: bash -*-

set -uo pipefail

basedir="$(cd "$(dirname "$0")/.." && pwd)"
CURRENT_DIR="$(cd "$(dirname "$0")/.." && pwd)"

default_workspace_dirs="${HOME}/develop/workspace"
tmux_option_workspace_dirs='@per-project-session-workspace-dirs'

default_known_project_dirs=''
tmux_option_known_project_dirs='@per-project-session-known-project-dirs'

default_max_depth=2
tmux_option_max_depth='@per-project-session-workspace-max-depth'

# shellcheck source=../lib/tmux.bash
. "${basedir}/lib/tmux.bash"
# shellcheck source=helpers.sh
. "${CURRENT_DIR}/helpers.sh"

executable() {
local name
Expand Down Expand Up @@ -64,10 +71,10 @@ find_projects() {
local workspace_dirs
local max_depth
IFS=':' read -r -a workspace_dirs \
< <(tmux_get_option '@per-project-session-workspace-dirs' "${HOME}/develop/workspace")
< <(get_tmux_option "$tmux_option_workspace_dirs" "$default_workspace_dirs")
IFS=':' read -ra known_project_dirs \
< <(tmux_get_option '@per-project-session-known-project-dirs' '')
max_depth="$(tmux_get_option '@per-project-session-workspace-max-depth' 2)"
< <(get_tmux_option "$tmux_option_known_project_dirs" "$default_known_project_dirs")
max_depth="$(get_tmux_option "$tmux_option_max_depth" $default_max_depth)"

{
for project_dir in "${known_project_dirs[@]}"; do
Expand Down Expand Up @@ -100,7 +107,7 @@ main() {
local fzf_tmux_opts
local project_dir
local session_name
fzf_tmux_opts="$(tmux_get_option '@per-project-session-fzf-tmux-opts' '-d 30%')"
fzf_tmux_opts="$(get_tmux_option '@per-project-session-fzf-tmux-opts' '-d 30%')"

project_dir="$(find_projects |
abbrev_path_stdin |
Expand Down

0 comments on commit 2079e5d

Please sign in to comment.