Skip to content

Commit

Permalink
MMVII: bash completion: make it work on Window
Browse files Browse the repository at this point in the history
  • Loading branch information
meynardc committed Feb 12, 2024
1 parent a83156a commit 6600a13
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
15 changes: 13 additions & 2 deletions MMVII/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Bash completion (beta)

It is possible to have MMVII command completion for Linux bash

- Requires: bash-completion python3
- Requires: python3

(Already installed by default on Ubuntu, just in case: sudo apt install bash-completion python3)

Expand All @@ -120,9 +120,20 @@ It is possible to have MMVII command completion for Linux bash
- MMVII executable must be in your $PATH
- Add to your ${HOME}/.bashrc the following line:

`[ -f ${HOME}/@MICMAC_SOURCE_DIR@/micmac/MMVII/bash-completion/mmvii-completion ] && . ${HOME}/@MICMAC_SOURCE_DIR@/micmac/MMVII/bash-completion/mmvii-completion ]`
`[ -f ${HOME}/@MICMAC_SOURCE_DIR@/micmac/MMVII/bash-completion/mmvii-completion ] && . ${HOME}/@MICMAC_SOURCE_DIR@/micmac/MMVII/bash-completion/mmvii-completion`
- Completion will be active in terminals opened after this modification.

If you're using bash on Windows, it may also works:

- You must have python >= 3.7 installed somewhere

- Edit your ~/.bash_profile and add: (adapt first 2 lines to your case)
```
MMVII_INSTALL_PATH=/c/micmac/MMVII
PYTHON_INSTALL_PATH=/c/Python/Python39/
PATH=${PYTHON_INSTALL_PATH}:${MMVII_INSTALL_PATH}/bin:$PATH
[ -f ${MMVII_INSTALL_PATH}/bash-completion/mmvii-completion ] && . ${MMVII_INSTALL_PATH}/bash-completion/mmvii-completion
```

vCommand (beta)
---------------
Expand Down
7 changes: 5 additions & 2 deletions MMVII/bash-completion/mmvii-completion
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _mmvii_completion()
export COMP_LINE COLUMNS
local cur cword
_get_comp_words_by_ref -n = cur cword
local RESULT="$(python3 - "$cur" "$cword" <<'EOT'
local RESULT="$(python - "$cur" "$cword" <<'EOT'
import sys
import os
import json
Expand All @@ -19,6 +19,9 @@ comp_cword=int(sys.argv[2])
comp_line=os.getenv('COMP_LINE')
screen_columns=int(os.getenv('COLUMNS','80'))
# For windows, force remove CR (^M) from output
sys.stdout.reconfigure(newline="\n")
helpArgPossible=True
if debug>1:
Expand Down Expand Up @@ -297,5 +300,5 @@ EOT
fi
}

complete -F _mmvii_completion MMVII
complete -F _mmvii_completion MMVII MMVII.exe mmvii mmvii.exe

3 changes: 3 additions & 0 deletions MMVII/bash-completion/mmvii-completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
comp_line=os.getenv('COMP_LINE')
screen_columns=int(os.getenv('COLUMNS','80'))

# For windows, force remove CR (^M) from output
sys.stdout.reconfigure(newline="\n")

helpArgPossible=True

if debug>1:
Expand Down
4 changes: 2 additions & 2 deletions MMVII/bash-completion/mmvii-completion.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _mmvii_completion()
export COMP_LINE COLUMNS
local cur cword
_get_comp_words_by_ref -n = cur cword
local RESULT="$(python3 - "$cur" "$cword" < ${_MMVII_COMPLETION_PYTHON})"
local RESULT="$(python - "$cur" "$cword" < ${_MMVII_COMPLETION_PYTHON})"
readarray -t COMPREPLY < <(echo -n "$RESULT")
if [ ${#COMPREPLY[@]} -eq 0 ]; then
unset COMPREPLY
Expand All @@ -26,5 +26,5 @@ _mmvii_completion()
}

_MMVII_COMPLETION_PYTHON=$(dirname ${BASH_SOURCE[0]})/mmvii-completion.py
complete -F _mmvii_completion MMVII
complete -F _mmvii_completion MMVII MMVII.exe mmvii mmvii.exe

0 comments on commit 6600a13

Please sign in to comment.