From 43605ac8b260472f86d0cc006eab8ab262a9cb48 Mon Sep 17 00:00:00 2001 From: edualb <39157101+edualb@users.noreply.github.com> Date: Tue, 11 Oct 2022 11:20:38 -0300 Subject: [PATCH] docs: tutorial for bash autocomplete (#24398) * including tutorial for bash autocomplete - included the Bash Autocomplete in sidebar.yml - created a new file called Bash-Autocomplete.md with a tutorial to include a bash autocomplete. This tutorial was based on: - https://github.com/urfave/cli/blob/master/docs/v1/manual.md#enabling - https://github.com/urfave/cli/blob/master/docs/v2/manual.md#powershell-support * Update docs/_interface/Bash-Autocomplete.md - From "Creates" to "Create" in Windows tutorial Co-authored-by: ligi * Update docs/_interface/Bash-Autocomplete.md - From "Creates" to "Create" in Linux/MacOS tutorial Co-authored-by: ligi * (_layouts): redirect to first element in documentation - Problem: The sidebar was redirecting to the wrong element in the list when we click on that. It was occuring because the logic inside of sidebar.html to build the list-group-item was carry about the frontdoc.url instead of the first element by itself. - Solution: We are sorting the collection.docs and then build the list-group-item with the right element in the list. Co-authored-by: ligi --- _data/sidebar.yml | 1 + _layouts/sidebar.html | 5 +-- docs/_interface/Bash-Autocomplete.md | 66 ++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 docs/_interface/Bash-Autocomplete.md diff --git a/_data/sidebar.yml b/_data/sidebar.yml index b46b588cad..d8f3776119 100644 --- a/_data/sidebar.yml +++ b/_data/sidebar.yml @@ -10,6 +10,7 @@ How to use: - Contract Tutorial: /docs/Contract-Tutorial Interface Documentation: - Command Line Options: /docs/Command-Line-Options + - Bash Autocomplete: /docs/Bash-Autocomplete - JavaScript Console: /docs/JavaScript-Console - Management API: /docs/Management-APIs - JSON-RPC server: https://github.com/ethereum/wiki/wiki/JSON-RPC diff --git a/_layouts/sidebar.html b/_layouts/sidebar.html index 615fd2c6b7..ca24dd8a97 100644 --- a/_layouts/sidebar.html +++ b/_layouts/sidebar.html @@ -11,11 +11,10 @@ layout: default {% unless frontdoc %} {% assign frontdoc = collection.docs[0] %} {% endunless %} - {% capture target %}{% include link.html url=frontdoc.url %}{% endcapture %} + {% assign docs_by_sort_key = collection.docs | group_by:"sort_key" | sort:"name", "last" %}
- {{ collection.caption }} + {{ collection.caption }} {% if page.collection == collection.label %} - {% assign docs_by_sort_key = collection.docs | group_by:"sort_key" | sort:"name", "last" %} {% for group in docs_by_sort_key %} {% assign docs_sorted = group.items | sort:"title" %} {% for doc in docs_sorted %} diff --git a/docs/_interface/Bash-Autocomplete.md b/docs/_interface/Bash-Autocomplete.md new file mode 100644 index 0000000000..e8ac731ccd --- /dev/null +++ b/docs/_interface/Bash-Autocomplete.md @@ -0,0 +1,66 @@ +--- +title: Bash Autocomplete +sort_key: C +--- + +You can enable autocompletion in geth just running a bash script (Linux/MacOS) or a powershell script (Windows). + +### Linux/MacOS + +1. Create a bash script file with the content below and save as `geth-autocompletion` anywhere in your computer (i.e. `/bin/geth-autocompletion`): + + ```bash + #! /bin/bash + + : ${PROG:=$(basename ${BASH_SOURCE})} + + _cli_bash_autocomplete() { + if [[ "${COMP_WORDS[0]}" != "source" ]]; then + local cur opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if [[ "$cur" == "-"* ]]; then + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) + else + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) + fi + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi + } + + complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG + unset PROG + ``` + +2. Open and edit your **startup script** depending on the terminal in use (i.e. `~/.bashrc` or `~/.zshrc`). + +3. Includes this command in the final of your **startup script**: + + ```bash + # i.e. PROG=geth source /bin/geth-autocompletion + PROG=geth source /path/to/autocomplete/geth-autocompletion-script + ``` + +### Windows + +1. Create a powershell script file with the content below and save as `geth.ps1` anywhere in your computer. + + ```bash + $fn = $($MyInvocation.MyCommand.Name) + $name = $fn -replace "(.*)\.ps1$", '$1' + Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock { + param($commandName, $wordToComplete, $cursorPosition) + $other = "$wordToComplete --generate-bash-completion" + Invoke-Expression $other | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } + } + ``` + +2. Open the PowerShell profile (`code $profile` or `notepad $profile`) and add the line: + + ```bash + & path/to/autocomplete/geth.ps1 + ``` +