-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mandos/develop
Customize session names + tests
- Loading branch information
Showing
11 changed files
with
458 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# IDE | ||
.idea | ||
|
||
# Nix | ||
.envrc | ||
.direnv | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# syntax = docker/dockerfile:1.4 | ||
FROM nixos/nix:2.22.0 AS builder | ||
|
||
WORKDIR /tmp/build | ||
RUN mkdir /tmp/nix-store-closure | ||
COPY . . | ||
|
||
RUN \ | ||
--mount=type=cache,target=/nix,from=nixos/nix:2.22.0,source=/nix \ | ||
--mount=type=cache,target=/root/.cache \ | ||
--mount=type=bind,target=/tmp/build \ | ||
<<EOF | ||
nix \ | ||
--extra-experimental-features "nix-command flakes" \ | ||
--option filter-syscalls false \ | ||
--show-trace \ | ||
--log-format raw \ | ||
build .#dev --out-link /tmp/output/result | ||
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure | ||
EOF | ||
|
||
|
||
FROM scratch | ||
|
||
WORKDIR /workspace | ||
|
||
COPY --from=builder /tmp/nix-store-closure /nix/store | ||
COPY --from=builder /tmp/output/ /workspace/ | ||
ENV PATH=/workspace/result/bin:$PATH | ||
RUN ["ln","-s", "/workspace/result/bin", "/bin"] | ||
RUN ["mkdir","-p", "/usr/bin"] | ||
RUN ["ln","-s", "/workspace/result/bin/env", "/usr/bin/env"] | ||
# For bats | ||
RUN ["mkdir","--mode", "1777", "/tmp"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
source "$CURRENT_DIR/../src/helpers.sh" | ||
|
||
# Usage: t <optional zoxide-like dir, relative or absolute path> | ||
# If no argument is given, a combination of existing sessions and a zoxide query will be displayed in a FZF | ||
|
||
# Parse optional argument | ||
if [ "$1" ]; then | ||
# Argument is given | ||
eval "$(zoxide init bash)" | ||
RESULT=$(z $@ && pwd) | ||
else | ||
# No argument is given. Use FZF | ||
RESULT=$( ( | ||
tmux list-sessions -F "#{session_last_attached} #{session_name}: #{session_windows} window(s)\ | ||
#{?session_grouped, (group ,}#{session_group}#{?session_grouped,),}#{?session_attached, (attached),}" | | ||
sort -r | (if [ -n "$TMUX" ]; then grep -v " $(tmux display-message -p '#S'):"; else cat; fi) | cut -d' ' -f2- | ||
zoxide query -l | sed -e "$HOME_REPLACER" | ||
) | $(__fzfcmd) --reverse --print-query | tail -n 1) | ||
if [ -z "$RESULT" ]; then | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# Makes sure tmux is running in order to get all the correct tmux options below. Gets cleaned at the bottom | ||
if ! tmux info &>/dev/null; then | ||
TMP_SESSION_DIR=$(mktemp -d) | ||
TMP_SESSION_NAME=$(session_name --full-path "$TMP_SESSION_DIR") | ||
tmux new-session -d -s "$TMP_SESSION_NAME" -c "$TMP_SESSION_DIR" | ||
fi | ||
|
||
# Get or create session | ||
if [[ $RESULT == *":"* ]]; then | ||
# RESULT comes from list-sessions | ||
SESSION=$(echo $RESULT | awk '{print $1}') | ||
SESSION=${SESSION//:/} | ||
else | ||
# RESULT is a path | ||
|
||
DIR_FULL=$(echo "$RESULT" | sed -e "s|^~/|$HOME/|") | ||
DIR_WITH_TILDE=$(echo "$RESULT" | sed -e "$HOME_REPLACER") # in case it came from a direct usage of `t <path>` | ||
|
||
# Quit if directory does not exists | ||
if [ ! -d "$DIR_FULL" ]; then | ||
exit 0 | ||
fi | ||
|
||
# Promote rank in zoxide. | ||
zoxide add "$DIR_FULL" | ||
|
||
MODE=$(get_tmux_option "@session-wizard-mode" "directory") | ||
SESSION=$(session_name --"$MODE" "$DIR_WITH_TILDE") | ||
|
||
if ! tmux has-session -t="$SESSION" 2>/dev/null; then | ||
tmux new-session -d -s "$SESSION" -c "$DIR_FULL" | ||
fi | ||
fi | ||
|
||
# Clean up tmp session | ||
if [[ -n "$TMP_SESSION_NAME" ]]; then | ||
tmux kill-session -t "$TMP_SESSION_NAME" 2>/dev/null | ||
rm -rf "$TMP_SESSION_DIR" | ||
fi | ||
|
||
# Attach to session | ||
# Escape tilde which if appears by itself, tmux will interpret as a marked target | ||
# https://github.com/tmux/tmux/blob/master/cmd-find.c#L1024C51-L1024C57 | ||
SESSION=$(echo "$SESSION" | sed 's/^~$/\\~/') | ||
if [ -z "$TMUX" ]; then | ||
tmux attach -t "$SESSION" | ||
else | ||
tmux switch-client -t "$SESSION" | ||
fi |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils, ... }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
devPackages = [ | ||
(pkgs.bats.withLibraries (p: [ p.bats-support p.bats-assert ])) | ||
pkgs.watchexec | ||
]; | ||
plugin = pkgs.tmuxPlugins.mkTmuxPlugin { | ||
pluginName = "session-wizard"; | ||
rtpFilePath = "session-wizard.tmux"; | ||
version = "unstable"; | ||
src = self; | ||
nativeBuildInputs = [ pkgs.makeWrapper ]; | ||
postInstall = '' | ||
ls -al $target && \ | ||
substituteInPlace $target/session-wizard.tmux \ | ||
--replace \$CURRENT_DIR/bin/t $target/bin/t | ||
wrapProgram $target/bin/t \ | ||
--prefix PATH : ${with pkgs; lib.makeBinPath ([ fzf zoxide coreutils gnugrep gnused ])} | ||
''; | ||
}; | ||
in | ||
{ | ||
packages.dev = (pkgs.symlinkJoin | ||
{ | ||
name = "dev-environment"; | ||
paths = [ | ||
plugin | ||
plugin.buildInputs | ||
pkgs.tmux | ||
pkgs.bashInteractive | ||
pkgs.busybox | ||
] ++ devPackages; | ||
}); | ||
|
||
devShell = pkgs.mkShell { | ||
buildInputs = devPackages; | ||
}; | ||
} | ||
); | ||
} |
Oops, something went wrong.