Command-line autocompletion for python -m module
Is it possible to get command-line autocompletion of python -m package.subpackage.module
?
This is similar to, but not the same as, python ./package/subpackage/module.py
, which does autocomplete the directory and file paths. However with -m
, python runs the library's module as a script with the appropriate namespacing and import paths.
I'd like to be able to do python -m package.s[TAB]
and get autocompletion to subpackage
.
Is this feature built in somewhere, or how can I set it up?
python bash autocomplete bash-completion
add a comment |
Is it possible to get command-line autocompletion of python -m package.subpackage.module
?
This is similar to, but not the same as, python ./package/subpackage/module.py
, which does autocomplete the directory and file paths. However with -m
, python runs the library's module as a script with the appropriate namespacing and import paths.
I'd like to be able to do python -m package.s[TAB]
and get autocompletion to subpackage
.
Is this feature built in somewhere, or how can I set it up?
python bash autocomplete bash-completion
1
The bash-completion tool is extensible.
– Klaus D.
Nov 12 '18 at 20:15
add a comment |
Is it possible to get command-line autocompletion of python -m package.subpackage.module
?
This is similar to, but not the same as, python ./package/subpackage/module.py
, which does autocomplete the directory and file paths. However with -m
, python runs the library's module as a script with the appropriate namespacing and import paths.
I'd like to be able to do python -m package.s[TAB]
and get autocompletion to subpackage
.
Is this feature built in somewhere, or how can I set it up?
python bash autocomplete bash-completion
Is it possible to get command-line autocompletion of python -m package.subpackage.module
?
This is similar to, but not the same as, python ./package/subpackage/module.py
, which does autocomplete the directory and file paths. However with -m
, python runs the library's module as a script with the appropriate namespacing and import paths.
I'd like to be able to do python -m package.s[TAB]
and get autocompletion to subpackage
.
Is this feature built in somewhere, or how can I set it up?
python bash autocomplete bash-completion
python bash autocomplete bash-completion
edited Nov 12 '18 at 21:34
Amessihel
2,6391824
2,6391824
asked Nov 12 '18 at 20:13
HatshepsutHatshepsut
1,39411126
1,39411126
1
The bash-completion tool is extensible.
– Klaus D.
Nov 12 '18 at 20:15
add a comment |
1
The bash-completion tool is extensible.
– Klaus D.
Nov 12 '18 at 20:15
1
1
The bash-completion tool is extensible.
– Klaus D.
Nov 12 '18 at 20:15
The bash-completion tool is extensible.
– Klaus D.
Nov 12 '18 at 20:15
add a comment |
1 Answer
1
active
oldest
votes
As said in the comment section, you need to extend the bash-completion tool. Then, you'll create a script which handles the cases you need (ie: when the last argument was -m
).
This little sample below shows a start for your custom completion script. Let's name it python_completion.sh
.
_python_target()
local cur prev opts
# Retrieving the current typed argument
cur="$COMP_WORDS[COMP_CWORD]"
# Retrieving the previous typed argument ("-m" for example)
prev="$COMP_WORDS[COMP_CWORD-1]"
# Preparing an array to store available list for completions
# COMREPLY will be checked to suggest the list
COMPREPLY=()
# Here, we'll only handle the case of "-m"
# Hence, the classic autocompletion is disabled
# (ie COMREPLY stays an empty array)
if [[ "$prev" != "-m" ]]
then
return 0
fi
# Retrieving paths and converts their separators into dots
# (if packages doesn't exist, same thing, empty array)
if [[ ! -e "./package" ]]
then
return 0
fi
# Otherwise, we retrieve first the paths starting with "./package"
# and converts their separators into dots
opts="$(find ./package -type d
complete -F _python_target python
(Warning. This script has a flaw, it won't work with filenames containing spaces). To test it, run it in the current environnement:
. ./python_completion.sh
And test it:
python -m packag[TAB]
Here is a tutorial to continue in this way.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269417%2fcommand-line-autocompletion-for-python-m-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As said in the comment section, you need to extend the bash-completion tool. Then, you'll create a script which handles the cases you need (ie: when the last argument was -m
).
This little sample below shows a start for your custom completion script. Let's name it python_completion.sh
.
_python_target()
local cur prev opts
# Retrieving the current typed argument
cur="$COMP_WORDS[COMP_CWORD]"
# Retrieving the previous typed argument ("-m" for example)
prev="$COMP_WORDS[COMP_CWORD-1]"
# Preparing an array to store available list for completions
# COMREPLY will be checked to suggest the list
COMPREPLY=()
# Here, we'll only handle the case of "-m"
# Hence, the classic autocompletion is disabled
# (ie COMREPLY stays an empty array)
if [[ "$prev" != "-m" ]]
then
return 0
fi
# Retrieving paths and converts their separators into dots
# (if packages doesn't exist, same thing, empty array)
if [[ ! -e "./package" ]]
then
return 0
fi
# Otherwise, we retrieve first the paths starting with "./package"
# and converts their separators into dots
opts="$(find ./package -type d
complete -F _python_target python
(Warning. This script has a flaw, it won't work with filenames containing spaces). To test it, run it in the current environnement:
. ./python_completion.sh
And test it:
python -m packag[TAB]
Here is a tutorial to continue in this way.
add a comment |
As said in the comment section, you need to extend the bash-completion tool. Then, you'll create a script which handles the cases you need (ie: when the last argument was -m
).
This little sample below shows a start for your custom completion script. Let's name it python_completion.sh
.
_python_target()
local cur prev opts
# Retrieving the current typed argument
cur="$COMP_WORDS[COMP_CWORD]"
# Retrieving the previous typed argument ("-m" for example)
prev="$COMP_WORDS[COMP_CWORD-1]"
# Preparing an array to store available list for completions
# COMREPLY will be checked to suggest the list
COMPREPLY=()
# Here, we'll only handle the case of "-m"
# Hence, the classic autocompletion is disabled
# (ie COMREPLY stays an empty array)
if [[ "$prev" != "-m" ]]
then
return 0
fi
# Retrieving paths and converts their separators into dots
# (if packages doesn't exist, same thing, empty array)
if [[ ! -e "./package" ]]
then
return 0
fi
# Otherwise, we retrieve first the paths starting with "./package"
# and converts their separators into dots
opts="$(find ./package -type d
complete -F _python_target python
(Warning. This script has a flaw, it won't work with filenames containing spaces). To test it, run it in the current environnement:
. ./python_completion.sh
And test it:
python -m packag[TAB]
Here is a tutorial to continue in this way.
add a comment |
As said in the comment section, you need to extend the bash-completion tool. Then, you'll create a script which handles the cases you need (ie: when the last argument was -m
).
This little sample below shows a start for your custom completion script. Let's name it python_completion.sh
.
_python_target()
local cur prev opts
# Retrieving the current typed argument
cur="$COMP_WORDS[COMP_CWORD]"
# Retrieving the previous typed argument ("-m" for example)
prev="$COMP_WORDS[COMP_CWORD-1]"
# Preparing an array to store available list for completions
# COMREPLY will be checked to suggest the list
COMPREPLY=()
# Here, we'll only handle the case of "-m"
# Hence, the classic autocompletion is disabled
# (ie COMREPLY stays an empty array)
if [[ "$prev" != "-m" ]]
then
return 0
fi
# Retrieving paths and converts their separators into dots
# (if packages doesn't exist, same thing, empty array)
if [[ ! -e "./package" ]]
then
return 0
fi
# Otherwise, we retrieve first the paths starting with "./package"
# and converts their separators into dots
opts="$(find ./package -type d
complete -F _python_target python
(Warning. This script has a flaw, it won't work with filenames containing spaces). To test it, run it in the current environnement:
. ./python_completion.sh
And test it:
python -m packag[TAB]
Here is a tutorial to continue in this way.
As said in the comment section, you need to extend the bash-completion tool. Then, you'll create a script which handles the cases you need (ie: when the last argument was -m
).
This little sample below shows a start for your custom completion script. Let's name it python_completion.sh
.
_python_target()
local cur prev opts
# Retrieving the current typed argument
cur="$COMP_WORDS[COMP_CWORD]"
# Retrieving the previous typed argument ("-m" for example)
prev="$COMP_WORDS[COMP_CWORD-1]"
# Preparing an array to store available list for completions
# COMREPLY will be checked to suggest the list
COMPREPLY=()
# Here, we'll only handle the case of "-m"
# Hence, the classic autocompletion is disabled
# (ie COMREPLY stays an empty array)
if [[ "$prev" != "-m" ]]
then
return 0
fi
# Retrieving paths and converts their separators into dots
# (if packages doesn't exist, same thing, empty array)
if [[ ! -e "./package" ]]
then
return 0
fi
# Otherwise, we retrieve first the paths starting with "./package"
# and converts their separators into dots
opts="$(find ./package -type d
complete -F _python_target python
(Warning. This script has a flaw, it won't work with filenames containing spaces). To test it, run it in the current environnement:
. ./python_completion.sh
And test it:
python -m packag[TAB]
Here is a tutorial to continue in this way.
edited Nov 12 '18 at 21:28
answered Nov 12 '18 at 21:22
AmessihelAmessihel
2,6391824
2,6391824
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269417%2fcommand-line-autocompletion-for-python-m-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The bash-completion tool is extensible.
– Klaus D.
Nov 12 '18 at 20:15