Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
## tmux sessionizer
# tmux sessionizer
its a script that does everything awesome at all times

## Usage
## Basic usage
```bash
tmux-sessionizer [<partial name of session>]
```

By default, tmux-sessionizer holds its state in .tmux-sessionizer.txt in your
$HOME directory, but this can be changed within the top of tmux-sessionizer
itself

## Options
-a, -add
Adds full filepaths to your tmux-sessionizer list via stdin or
interactive mode. It will automatically reject duplicates, and will
only accept valid absolute filepaths to folders that exist.

-d, -delete
Opens a multi-select fzf of your current tmux-sessionizer list which
can be used to delete files in your list by selecting either one file
to delete using the enter key, or multiple files using tab to select
multiple files and then enter to delete those files. CTRL-C to exit

-l, -list
Lists the contents of the tmux-sessionizer list.

### Example commands
Add all directories within the current working directory to your list.
```bash
find $(pwd) -maxdepth 1 -type d | tmux-sessionizer -a
```

Enter fzf and delete folders in your tmux-sessionizer list by selecting them
with tab and then clicking enter
```bash
tmux-sessionizer -d
```

List all the directories in your tmux-sessionizer list
```bash
tmux-sessionizer -l
```

if you execute tmux-sessionizer without any parameters it will assume FZF and
try to fuzzy find over a set of directories.

TODO: waiting on that directory list to be dynamic :) (go a head make pr if you want)
55 changes: 51 additions & 4 deletions tmux-sessionizer
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
#!/usr/bin/env bash
#/usr/bin/env bash

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct shebang else this will not run.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#script_dir="$(dirname "$(realpath "$0")")"
script_dir="$HOME"
file_name=".tmux-sessionizer.txt"
full_path="$script_dir/$file_name"

if [[ ! -e "$full_path" ]]; then
touch "$full_path"
fi

# Add flags for adding, deleting or listing files
if [[ $# -eq 1 ]]; then

# add a path to our tmux save file, this accepts stdin and also prevents
# duplicates
if [[ $1 == -add || $1 == -a ]]; then
while read line; do
# ensure that the filepath is absolute and it exists
if [[ -d $line && "$line" = /* ]]; then
if ! grep -qFx $line $full_path; then
echo "$line" >> $full_path
fi
fi
done < "${2:-/dev/stdin}"

# delete a path from our tmux save file. You can select multiple files to
# delete using the tab key in fzf to select multiple
elif [[ $1 == -delete || $1 == -d ]]; then
while true; do
selected=$(cat "$full_path" | fzf -m)

if [[ -z "$selected" ]]; then
exit 0
fi

count=$(echo "$selected" | wc -l)

if [[ $count -gt 0 ]]; then
temp_file=$(mktemp)
grep -v -F -x -e "$selected" "$full_path" > "$temp_file"
mv "$temp_file" "$full_path"
fi
done
elif [[ $1 == -list || $1 == -l ]]; then
cat $full_path
fi
exit 0
fi

# switching tmux to the files
switch_to() {
if [[ -z $TMUX ]]; then
tmux attach-session -t $1
Expand All @@ -22,9 +71,7 @@ hydrate() {
if [[ $# -eq 1 ]]; then
selected=$1
else
# If someone wants to make this extensible, i'll accept
# PR
selected=$(find ~/ ~/personal ~/personal/dev/env/.config -mindepth 1 -maxdepth 1 -type d | fzf)
selected=$(cat $full_path| fzf)
fi

if [[ -z $selected ]]; then
Expand Down