diff --git a/README.md b/README.md index 8599829..8ca81b3 100644 --- a/README.md +++ b/README.md @@ -356,6 +356,10 @@ auto-cpufreq should be run with with one of the following options: * help - Shows all of the above options +* completions=TEXT + - To support shell completions (currently bash, zsh and fish) + - TEXT can be bash, zsh or fish (shell name) + Running `auto-cpufreq --help` will print the same list of options as above. Read [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options) for more details. ## auto-cpufreq modes and options diff --git a/auto_cpufreq/bin/auto_cpufreq.py b/auto_cpufreq/bin/auto_cpufreq.py index 3f9e470..f3d9fc3 100755 --- a/auto_cpufreq/bin/auto_cpufreq.py +++ b/auto_cpufreq/bin/auto_cpufreq.py @@ -34,9 +34,10 @@ from auto_cpufreq.power_helper import * @click.option("--debug", is_flag=True, help="Show debug info (include when submitting bugs)") @click.option("--version", is_flag=True, help="Show currently installed version") @click.option("--donate", is_flag=True, help="Support the project") +@click.option("--completions", is_flag=False, help="Enables shell completions for bash, zsh and fish.\n Possible values bash|zsh|fish") @click.option("--log", is_flag=True, hidden=True) @click.option("--daemon", is_flag=True, hidden=True) -def main(config, daemon, debug, update, install, remove, live, log, monitor, stats, version, donate, force, get_state): +def main(config, daemon, debug, update, install, remove, live, log, monitor, stats, version, donate, force, get_state, completions): # display info if config file is used def config_info_dialog(): @@ -50,7 +51,6 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta set_override(force) # Calling set override, only if force has some values if len(sys.argv) == 1: - print("\n" + "-" * 32 + " auto-cpufreq " + "-" * 33 + "\n") print("Automatic CPU speed & power optimizer for Linux") @@ -265,5 +265,22 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta else: print("Aborted") + elif completions: + if completions == "bash": + print("Run the below command in your current shell!\n") + print("echo 'eval \"$(_AUTO_CPUFREQ_COMPLETE=bash_source auto-cpufreq)\"' >> ~/.bashrc") + print("source ~/.bashrc") + elif completions == "zsh": + print("Run the below command in your current shell!\n") + print("echo 'eval \"$(_AUTO_CPUFREQ_COMPLETE=zsh_source auto-cpufreq)\"' >> ~/.zshrc") + print("source ~/.zshrc") + elif completions == "fish": + print("Run the below command in your current shell!\n") + print("echo '_AUTO_CPUFREQ_COMPLETE=fish_source auto-cpufreq | source' > ~/.config/fish/completions/auto-cpufreq.fish") + else: + print("Invalid Option, try bash|zsh|fish as argument to --completions") + + + if __name__ == "__main__": main() diff --git a/scripts/auto-cpufreq-venv-wrapper b/scripts/auto-cpufreq-venv-wrapper index d35d4db..c3b8596 100644 --- a/scripts/auto-cpufreq-venv-wrapper +++ b/scripts/auto-cpufreq-venv-wrapper @@ -15,20 +15,21 @@ err_exit() # invocation handling # -param="" -if [ "${#}" -ne 1 ]; -then - err_exit -else - param="${1}" -fi + # load python virtual environment venv_dir=/opt/auto-cpufreq/venv . "${venv_dir}/bin/activate" # run python code with venv loaded -PYTHONPATH=/opt/auto-cpufreq \ +if [[ "${#}" -ne 1 ]]; then + PYTHONPATH=/opt/auto-cpufreq \ + /opt/auto-cpufreq/venv/bin/python \ + /opt/auto-cpufreq/venv/bin/auto-cpufreq +else + param="${1}" + PYTHONPATH=/opt/auto-cpufreq \ /opt/auto-cpufreq/venv/bin/python \ /opt/auto-cpufreq/venv/bin/auto-cpufreq \ "${param}" +fi