First you need a script like this in your terminal. It will detect all your projects, format them with a date when last used, sort them and pass through fzf. When a project has been selected it will cd to that directory and by default run tn
which is another script for creating a new tmux session from the current directory. If you run proj something
it will run that instead inside that directory.
$HOME/.zshrc
or similar
proj() {
local project_cmd=("$@")
local project_dir=$($HOME/.scripts/proj)
echo "$project_dir"
[[ $? -gt 0 ]] && return 1
cd "$project_dir"
if [[ ${#project_cmd[@]} -eq 0 ]]; then
tn
else
"${project_cmd[@]}" "$project_dir"
fi
}
brew install fzf findutils tmux
gem install tmuxinator
$HOME/.scripts/proj
#!/usr/bin/env bash
set -e
main() {
result="$(find_projects | gsort -r | fzf "$@")"
project=$(echo "$result" | cut -d ' ' -f3)
command=("$@")
[[ $? -eq 0 ]] || exit 1
echo "$project"
exit 0
}
find_projects() {
find_in "$HOME/Dev/github" 2
find_in "$HOME/Dev/bitbucket" 2
find_in "$HOME/Dev/Experiments" 1
find_in "$HOME/Dev/go/src" 3
}
find_in() {
find_all_folders "${1:?}" "${2:?}" | grep -v '.git$'
}
find_all_folders() {
gfind "${1:?}" \
-mindepth "${2:?}" \
-maxdepth "${2:?}" \
-type d \
-printf '%TY-%Tm-%Td %TH:%TM:%.2TS %p\n'
}
with_datestamp() {
while read project; do
echo "$(stat -f "%Sm" -t "%Y-%m-%d %H:%M" "$project") $project"
done
}
main "$@"
$HOME/.bin/tn
#!/usr/bin/env bash
set -e
# Use matching tmuxinator project
for project in "$HOME"/.config/tmuxinator/*; do
name=$(grep -E -m 1 "^name:" "$project" | cut -d ' ' -f2)
root=$(grep -E -m 1 "^root:" "$project" | cut -d ' ' -f2)
[[ "$PWD" != "$root"* ]] && continue
tmuxinator start "$name" || break
exit 0
done
session_name="$(basename "$PWD" | sed -e "s/\./\-/g")"
tmuxinator start default -n "$session_name" "$PWD"
$HOME/.config/tmuxinator/default.yml
root: <%= args[0] %>
windows:
- editor:
layout: main-vertical
panes:
- NVIM_LISTEN_ADDRESS="/tmp/nvimsocket-<%= args[0] %>" nvim README.md +:G