Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dotfiles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STEVAN Antoine
dotfiles
Commits
b66fedd2
Verified
Commit
b66fedd2
authored
1 month ago
by
STEVAN Antoine
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
72e9e686
Branches
tmux-sessionizer
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.config/tmux/sessionizer.nu
+136
-0
136 additions, 0 deletions
.config/tmux/sessionizer.nu
.config/tmux/tmux.conf
+26
-14
26 additions, 14 deletions
.config/tmux/tmux.conf
with
162 additions
and
14 deletions
.config/tmux/sessionizer.nu
0 → 100644
+
136
−
0
View file @
b66fedd2
def lpad [width: int, --character: string = " "]: [ string -> string ] { fill --alignment right --width $width --character $character }
def rpad [width: int, --character: string = " "]: [ string -> string ] { fill --alignment left --width $width --character $character }
def "str color" [color: string]: [ string -> string ] { $"(ansi $color)($in)(ansi reset)" }
const DEFAULT_FINDER = "~/documents/bin/find-git-repos-e96486f52751828ff5f8ebdfadacbd37cdb802afa559d098bbd59cac4df8b46d" | path expand
const SESSION_FILE = $nu.home-path | path join ".local" "state" "tmux" "last-session"
const LOG_FILE = "/tmp/log.txt"
def log [msg: string] { $"($msg)" out>> $LOG_FILE }
def logln [msg: string] { $"($msg)\n" out>> $LOG_FILE }
def get [
root : path,
--finder (-f) : string = $DEFAULT_FINDER,
--no-ansi (-A),
--sort (-s),
]: [
nothing -> record<
root : path,
host : string,
group : string,
project : string,
path : path,
>
] {
if not ($finder | path exists) {
error make {
msg: $"(ansi red_bold)unknown_finder(ansi reset)",
label: {
text: $"(ansi purple)($finder)(ansi reset): no such file",
span: (metadata $finder).span,
},
}
}
let finder = $finder | path expand
let repos = ^$finder $root | lines | if $sort { sort } else { $in } | each {
str replace --regex $"^($root)/" ''
| path split
| {
host: $in.0,
group: ($in | skip 1 | reverse | skip 1 | reverse | str join "/"),
project: ($in | last),
}
}
let width = {
host: ($repos.host | str length | math max),
group: ($repos.group | str length | math max),
project: ($repos.project | str length | math max),
}
try {
$repos
| insert display {
update host { rpad $width.host | if $no_ansi { $in } else { str color "cyan_dimmed" } }
| update group { rpad $width.group | if $no_ansi { $in } else { str color "default_dimmed" } }
| update project { rpad $width.project | if $no_ansi { $in } else { str color "yellow" } }
| $"($in.host) ($in.group) ($in.project)"
}
| input list --fuzzy --display display
| reject display
| insert root $root
| select root host group project
| insert path { values | path join }
} catch {
null
}
}
def get-current-session []: [ nothing -> string ] {
^tmux display-message -p '#{session_name}' | str trim
}
def get-previous-session []: [ nothing -> string ] {
$SESSION_FILE | if ($in | path exists) { open $in | str trim } else { "" }
}
def list-sessions []: [ nothing -> list<string> ] {
^tmux list-sessions -F "#{session_name}" | lines
}
def save-session [current: string] {
log $"save-session `($current)`"
mkdir ($SESSION_FILE | path dirname)
let previous = get-previous-session
if $previous != $current {
logln " (saved)"
$current | save --force $SESSION_FILE
} else {
logln ""
}
}
def switch-to-session [name: string] {
logln $"switch-to-session `($name)`"
^tmux switch-client -t $name
}
def create-session [name: string, --path: path] {
logln $"create-session `($name)`"
^tmux new-session -ds $name -c $path
}
def switch-to-or-create-session [name: string, --path: path = $nu.home-path] {
logln $"switch-to-or-create-session `($name)`"
if $name not-in (list-sessions) {
create-session $name --path $path
}
switch-to-session $name
}
def alternate-session [] {
let current = get-current-session
let previous = get-previous-session
logln "alternate-session"
logln $" previous : ($previous)"
logln $" current : ($current)"
if $previous in (list-sessions) {
save-session $current
switch-to-session $previous
}
}
def "path shorten" []: [ string -> string ] {
path split
| each {
if ($in | str starts-with '.') {
str substring ..1
} else {
str substring ..0
}
}
| path join
}
This diff is collapsed.
Click to expand it.
.config/tmux/tmux.conf
+
26
−
14
View file @
b66fedd2
...
...
@@ -25,7 +25,7 @@ bind-key -T copy-mode-vi t send-keys -X rectangle-toggle
bind
-
key
-
T
copy
-
mode
-
vi
y
send
-
keys
-
X
copy
-
pipe
-
and
-
cancel
'wl-copy'
# sessionizer
TMUX_
SESSIONIZER
=
"tmux
-
sessionizer.nu"
SESSIONIZER
=
"
~/.config/
tmux
/
sessionizer.nu"
FIND_GIT_REPOS_DIR
=
"~/documents/bin"
FIND_GIT_REPOS_SHA
=
"e96486f52751828ff5f8ebdfadacbd37cdb802afa559d098bbd59cac4df8b46d"
FIND_GIT_REPOS_BIN
=
"$FIND_GIT_REPOS_DIR/find-git-repos-$FIND_GIT_REPOS_SHA"
...
...
@@ -38,20 +38,32 @@ TMUX_SESSIONIZER_KEY="a"
TMUX_SESSIONIZER_PREFIX
=
"prefix_$TMUX_SESSIONIZER_KEY"
bind
-
key
-
T
prefix
$
TMUX_SESSIONIZER_KEY
switch
-
client
-
T
$
TMUX_SESSIONIZER_PREFIX
CTX
=
"nu --env-config ~/.config/nushell/env.nu --commands '$TMUX_SESSIONIZER"
TSP
=$
TMUX_SESSIONIZER_PREFIX
bind
-
key
-
r
-
T
$
TSP
h
display
-
popup
-
EE
-
w
$
W
-
h
$
H
-
y
0
"$CTX ...($FIND_GIT_REPOS_BIN ~/documents/repos/ | lines) --short'"
bind
-
key
-
r
-
T
$
TSP
n
run
-
shell
"$CTX new-session'"
bind
-
key
-
r
-
T
$
TSP
s
display
-
popup
-
EE
-
w
$
W
-
h
$
H
-
y
0
"$CTX switch-session'"
bind
-
key
-
r
-
T
$
TSP
r
display
-
popup
-
EE
-
w
$
W
-
h
$
H
-
y
0
"$CTX remove-sessions'"
bind
-
key
-
r
-
T
$
TSP
%
run
-
shell
"$CTX alternate'"
bind
-
key
-
r
-
T
$
TSP
e
display
-
popup
-
EE
-
w
$
W
-
h
$
H
-
y
0
"$CTX harpoon edit'"
bind
-
key
-
r
-
T
$
TSP
j
display
-
popup
-
EE
-
w
$
W
-
h
$
H
-
y
0
"$CTX harpoon entries'"
bind
-
key
-
r
-
T
$
TSP
a
run
-
shell
"$CTX harpoon add'"
bind
-
key
-
r
-
T
$
TSP
1
run
-
shell
"$CTX harpoon jump 0'"
bind
-
key
-
r
-
T
$
TSP
2
run
-
shell
"$CTX harpoon jump 1'"
bind
-
key
-
r
-
T
$
TSP
3
run
-
shell
"$CTX harpoon jump 2'"
bind
-
key
-
r
-
T
$
TSP
4
run
-
shell
"$CTX harpoon jump 3'"
bind
-
key
-
r
-
T
$
TSP
h
display
-
popup
-
EE
-
w
$
W
-
h
$
H
-
y
0
"
nu
--
commands
'
source
$
SESSIONIZER
; \
const
UCOLON
=
char
-
u
\
"2236\"
; \
const
UDOT
=
char
-
u
\
"2024\"
; \
\
let
res
=
get
-
sA
~/
documents
/
repos
/ --
finder
$
FIND_GIT_REPOS_BIN
; \
if
\$
res
!=
null
{ \
let
name
= \$\
"(\$res.host)(\$UCOLON)(\$res.group)/(\$res.project)\"
\
|
str
replace
--
all
\
".\"
\$
UDOT
; \
let
current
=
get
-
current
-
session
; \
logln
\
"\"
; \
logln
\$\
"SWITCH from (\$current) to (\$name)\"
; \
if
\$
current
!= \$
name
{ \
save
-
session
\$
current
; \
}; \
switch
-
to
-
or
-
create
-
session
\$
name
--
path
\$
res
.
path
; \
} \
'"
# bind-key -r -T $TSP n run-shell "$CTX new-session'"
# bind-key -r -T $TSP s display-popup -EE -w $W -h $H -y 0 "$CTX switch-session'"
# bind-key -r -T $TSP r display-popup -EE -w $W -h $H -y 0 "$CTX remove-sessions'"
bind
-
key
-
r
-
T
$
TSP
%
run
-
shell
"
nu
--
commands
'
source
$
SESSIONIZER
; \
logln
\
"\"
; \
logln
\
"ALTERNATE\"
; \
alternate
-
session
; \
'"
# from https://github.com/codingjerk/dotfiles/blob/main/config/tmux/tmux.conf
# Theme: borders
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment