Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Select a project from a fed list of projects
- # selected=$(cat ~/.tmux-projects-list | fzf)
- selected=$(find ~/Desktop ~/Downloads ~/Projects -maxdepth 5 -type d | fzf )
- # Does tilda substitution for support with different shells
- fix_selected=${selected/#~/$HOME}
- # Bail if nothing is selected
- if [[ -z $selected ]]; then
- exit 0
- fi
- # Bail if selection does not exists
- if [[ ! -d $fix_selected ]]; then
- tmux neww bash -c "echo -n \"No such file or directory: $selected\" & while [ : ]; do sleep 1; done"
- exit 0
- fi
- # Changes directory to the project directory
- # so that git and telescope work fine
- cd $fix_selected
- # Asks for a file to be opened directly
- file=$(fzf --bind enter:accept-or-print-query)
- # If the file does not exists it will create the file
- # Accidentally created files can be easily managed with git. ( e.g. Typos )
- if [[ ! -f "$fix_selected/$file" ]]; then
- touch "$fix_selected/$file"
- fi
- selected_name=$(basename $fix_selected)
- tmux_running=$(pgrep tmux)
- if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
- tmux new-session $fix_selected -c $fix_selected
- exit 0
- fi
- if ! tmux has-session -t=$selected_name 2> /dev/null; then
- tmux new-session -ds $selected_name -c $fix_selected
- fi
- tmux switch-client -t $selected_name
- # Opens a new tmux window with neovim editing the selected file
- tmux neww -n $(basename $selected) -t $selected_name bash -c "nvim $selected/$file"
Advertisement
Add Comment
Please, Sign In to add comment