Get a fish shell for working with gcloud command line tools?

Is anyone really lucky using the google gcloud command line tools? I am not an expert in Fish script, but these are two files that gcloud needs to run (which work fine in Fish bash mode). Fish does not allow you to export bash files from what I understand, so should they be converted to a Fish script?

path.bash

script_link="$( readlink "$BASH_SOURCE" )" || script_link="$BASH_SOURCE" apparent_sdk_dir="${script_link%/*}" if [ "$apparent_sdk_dir" == "$script_link" ]; then apparent_sdk_dir=. fi sdk_dir="$( command cd -P "$apparent_sdk_dir" && pwd -P )" bin_path="$sdk_dir/bin" export PATH=$bin_path:$PATH 

path.completion

 _python_argcomplete() { local IFS='' COMPREPLY=( $(IFS="$IFS" COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT" _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" _ARGCOMPLETE=1 "$1" 8>&1 9>&2 1>/dev/null 2>/dev/null) ) if [[ $? != 0 ]]; then unset COMPREPLY fi } complete -o default -F _python_argcomplete "gcloud" _completer() { command=$1 name=$2 eval '[[ "$'"${name}"'_COMMANDS" ]] || '"${name}"'_COMMANDS="$('"${command}"')"' set -- $COMP_LINE shift while [[ $1 == -* ]]; do shift done [[ $2 ]] && return grep -q "${name}\s*$" <<< $COMP_LINE && eval 'COMPREPLY=($'"${name}"'_COMMANDS)' && return [[ "$COMP_LINE" == *" " ]] && return [[ $1 ]] && eval 'COMPREPLY=($(echo "$'"${name}"'_COMMANDS" | grep ^'"$1"'))' } unset bq_COMMANDS _bq_completer() { _completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 bq help | grep '^[^ ][^ ]* ' | sed 's/ .*//'" bq } unset gsutil_COMMANDS _gsutil_completer() { _completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 gsutil help | sed /Additional/q | grep '^ ' | sed -e 's/^ //' -e 's/ .*//'" gsutil } unset gcutil_COMMANDS _gcutil_completer() { _completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 gcutil help | grep -v '^information' | grep '^[az]' | sed -e 's/ .*//' -e '/^$/d'" gcutil } complete -o default -F _bq_completer bq complete -o default -F _gsutil_completer gsutil complete -o default -F _gcutil_completer gcutil 
+10
source share
5 answers

What worked for me was just using bass. Check this out: https://github.com/edc/bass

Just take the lines that gcloud adds to your bash_profile file and add the bass to them in your .config/fish/config.fish file as follows:

 # The next line updates PATH for the Google Cloud SDK. bass source '/Users/hunter/bin/google-cloud-sdk/path.bash.inc' # The next line enables shell command completion for gcloud. bass source '/Users/hunter/bin/google-cloud-sdk/completion.bash.inc' 
+23
source

For path.bash, all it does is add the bin Cloud SDK directory to your PATH. We put some strange things there because we wanted it to work from the Cloud SDK directory even behind, for example, a symbolic link. For your own system, simply do the equivalent of fsh "export PATH = $ PATH: / path / to / google-cloud-sdk / bin".

To complete the tab, I don't know how the completion of the fsh tab works, so I have nothing.

+4
source

Fish support is now included out of the box with gcloud, however I ran into a rather annoying problem. The code included in google-cloud-sdk/path.fish.inc (and @nafg answer) leaves the directory changed, as a result, each new shell session starts in the google-cloud-sdk directory.

The modification I did was pretty simple, adding two extra lines to get the current working directory and restore it later. This seems to have resolved the issue for me, so hopefully helps any other person looking for problems with the gcloud fish.

 set restore_dir (pwd -P) set sdk_dir (builtin cd "$apparent_sdk_dir" > /dev/null; and pwd -P) set bin_path "$sdk_dir/bin" cd "$restore_dir" 
+2
source

Here's an interesting approach: http://michelpm.com/blog/2013/07/26/switching-from-zsh-to-fish/

Basically it will run a bash script in bash, but it will be different from how it modifies the environment and applies it to the fish.

However, it will not work for improvements and for your path. More like:

  • Change var = value to set var value
  • Change [...] to check ...
  • Change $ (...) to (...)
  • if not needed then and ends with end
  • Change || on ; or ; or and && on ; and ; and
  • Change export to install -x

So, without testing here, I would try:

 set script_link ( readlink "$BASH_SOURCE" ); or set script_link $BASH_SOURCE set apparent_sdk_dir ${script_link%/*} if test "$apparent_sdk_dir" == "$script_link" ; set apparent_sdk_dir . end set sdk_dir ( command cd -P "$apparent_sdk_dir"; and pwd -P ) set bin_path $sdk_dir/bin set -x PATH $bin_path:$PATH 
0
source

Today I could just do

  1. brew cask install google-cloud-sdk
  2. Added source/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.fish.inc for my ~/.config/fish/config.fish
  3. Clone https://github.com/aliz-ai/google-cloud-sdk-fish-completion, then run install.sh .
0
source

Source: https://habr.com/ru/post/974259/


All Articles