├── lazygit └── config.yml ├── scripts ├── helpers.sh ├── open-lazygit.sh └── editor.sh ├── neolazygit.tmux └── README.md /lazygit/config.yml: -------------------------------------------------------------------------------- 1 | promptToReturnFromSubprocess: false 2 | os: 3 | edit: '$LAZYGIT_EDITOR {{filename}}' 4 | editAtLine: '$LAZYGIT_EDITOR {{filename}} {{line}}' 5 | editAtLineAndWait: '$LAZYGIT_EDITOR {{filename}} {{line}}' 6 | editInTerminal: true 7 | openDirInEditor: '$LAZYGIT_EDITOR {{dir}}' 8 | -------------------------------------------------------------------------------- /scripts/helpers.sh: -------------------------------------------------------------------------------- 1 | # tmux show-option "q" (quiet) flag does not set return value to 1, even though 2 | # the option does not exist. This function patches that. 3 | get_tmux_option() { 4 | local option=$1 5 | local default_value=$2 6 | local option_value=$(tmux show-option -gqv "$option") 7 | if [ -z "$option_value" ]; then 8 | echo "$default_value" 9 | else 10 | echo "$option_value" 11 | fi 12 | } 13 | -------------------------------------------------------------------------------- /neolazygit.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 3 | 4 | source "$CURRENT_DIR/scripts/helpers.sh" 5 | 6 | default_key_bindings_openlazygit="G" 7 | tmux_option_open_lazygit="@open-lazygit" 8 | 9 | 10 | set_open_lazygit_key_bindings () { 11 | local key_bindings=$(get_tmux_option "$tmux_option_open_lazygit" "$default_key_bindings_openlazygit") 12 | local key 13 | for key in $key_bindings; do 14 | tmux bind "$key" run "$CURRENT_DIR/scripts/open-lazygit.sh" 15 | done 16 | } 17 | 18 | main () { 19 | set_open_lazygit_key_bindings 20 | } 21 | 22 | main 23 | -------------------------------------------------------------------------------- /scripts/open-lazygit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | CUSTOM_LAZYGIT_CONFIG="$CURRENT_DIR/../lazygit/config.yml" 5 | LAZYGIT_EDITOR="$CURRENT_DIR/editor.sh" 6 | LAZYGIT_CONFIG="$(lazygit -cd)/config.yml" 7 | 8 | openLazygit() { 9 | local ORIGIN_PANE 10 | ORIGIN_PANE="$(tmux display-message -p "#D")" 11 | 12 | local CURRENT_PATH 13 | CURRENT_PATH="$(tmux display-message -p -t "$ORIGIN_PANE" "#{pane_current_path}")" 14 | 15 | local WINDOW_NAME 16 | WINDOW_NAME="LG-${ORIGIN_PANE//%/}" 17 | 18 | # check exist window 19 | if tmux list-windows -F "#{window_name}" | grep -Fxq "$WINDOW_NAME"; then 20 | # switch to window 21 | tmux select-window -t "$WINDOW_NAME" 22 | else 23 | # else create new window 24 | tmux neww -n "$WINDOW_NAME" -c "$CURRENT_PATH" \ 25 | -e LAZYGIT_EDITOR="$LAZYGIT_EDITOR" \ 26 | -e LAZYGIT_ORIGIN_PANE="$ORIGIN_PANE" \ 27 | lazygit \ 28 | -ucf "$LAZYGIT_CONFIG,$CUSTOM_LAZYGIT_CONFIG" 29 | fi 30 | } 31 | 32 | openLazygit 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Neolazygit 2 | 3 | Use [lazygit](https://github.com/jesseduffield/lazygit) and neovim inside 4 | tmux as if they were always meant to be together 😃. 5 | 6 | ## Crappy demo 🤙 7 | 8 | ![neolazygit-demo](https://i.imgur.com/OBFzJNk.gif) 9 | 10 | ## Installation 11 | 12 | ### Using [TPM](https://github.com/tmux-plugins/tpm) (recommended) 13 | 14 | Add plugin to the list of *TPM* plugins. 15 | 16 | ```bash 17 | set -g @plugin 'AngryMorrocoy/tmux-neolazygit' 18 | ``` 19 | 20 | And press **prefix+I** to install it. 21 | 22 | ### Manual installation 23 | 24 | Clone this repo: 25 | 26 | ```bash 27 | $ git clone https://github.com/AngryMorrocoy/tmux-neolazygit 28 | ``` 29 | 30 | Add this line to your **tmux.conf** 31 | 32 | ```bash 33 | run-shell /neolazygit.tmux 34 | ``` 35 | 36 | Reload your TMUX environment: 37 | 38 | ```bash 39 | $ tmux source-file 40 | ``` 41 | 42 | ## Configuration options 43 | 44 | ### `@open-lazygit` 45 | 46 | **Default: G (shift+g)** 47 | 48 | Key used to open lazygit. 49 | 50 | ```bash 51 | set -g @open-lazygit 'G' 52 | ``` 53 | -------------------------------------------------------------------------------- /scripts/editor.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # A script that opens nvim from lazygit, if it was opened from a tmux pane, checks 3 | # if exists a nvim remote server for that pane 4 | 5 | # "editor.sh {{editor}} {{filename}} {{line}}" 6 | 7 | FILENAME=$1 8 | LINE=${2:-0} 9 | 10 | # Check if there's a nvim instance in the origin pane and 'returns' its server socket, 11 | # otherwise returns 0 12 | get_nvim_socket () { 13 | local pid_of_origin=$(tmux list-panes -sF "#{pane_pid}" \ 14 | -f "#{m:#{pane_id},${LAZYGIT_ORIGIN_PANE}}") 15 | 16 | if [ -z $pid_of_origin ]; then 17 | echo 0 18 | return 19 | fi 20 | 21 | # Gets all "nvim" processes running in the pane of origin 22 | NVIM_PIDS=$(pstree -paT $pid_of_origin | \ 23 | grep -E .\+nvim, | \ 24 | cut -d, -f2 | \ 25 | cut -d" " -f1) 26 | 27 | # Find the first PID that has an nvim socket assigned 28 | for nvim_pid in $NVIM_PIDS; do 29 | nvim_socket=$(ls ${XDG_RUNTIME_DIR}/nvim* 2>/dev/null | grep $nvim_pid) 30 | # Returns the found socket 31 | if [ ! -z $nvim_socket ]; then 32 | echo $nvim_socket 33 | return 34 | fi 35 | done 36 | 37 | echo 0 38 | } 39 | 40 | focus_nvim() { 41 | local origin_window=$(tmux list-panes -sF "#I" -f "#{m:#D,${LAZYGIT_ORIGIN_PANE}}") 42 | 43 | tmux selectw -t $origin_window 44 | tmux selectp -t $LAZYGIT_ORIGIN_PANE 45 | } 46 | 47 | 48 | main() { 49 | local socket=$(get_nvim_socket) 50 | # If no socket, it means no nvim, so just open inside lazygit ;) 51 | if [[ $socket == 0 ]]; then 52 | nvim +$LINE "$FILENAME" 53 | exit 0 54 | fi 55 | 56 | focus_nvim 57 | 58 | # Opens the file remotely in the expected line 59 | nvim --server "$socket" --remote "$(realpath "$FILENAME")" 60 | nvim --server "$socket" --remote-send "${LINE}gg" 61 | } 62 | 63 | main 64 | --------------------------------------------------------------------------------