Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use in fish shell #92

Closed
furudean opened this issue Feb 13, 2020 · 11 comments
Closed

Cannot use in fish shell #92

furudean opened this issue Feb 13, 2020 · 11 comments

Comments

@furudean
Copy link

furudean commented Feb 13, 2020

On a new setup, I'm aliasing the script as of #71, however there appears to be some kind of syntax that breaks in fish.

$ ~ bass "alias awsume=\"source /usr/local/bin/awsume\""
$ ~ awsume profile
/usr/local/bin/awsume (line 5): Expected a string, but instead found a redirection
read AWSUME_FLAG AWSUME_1 AWSUME_2 AWSUME_3 AWSUME_4 AWSUME_5 AWSUME_6 <<< $(awsumepy "$@")
                                                                        ^
from sourcing file /usr/local/bin/awsume
	called on line 1 of file -
in function 'awsume' with arguments 'profile'
source: Error while reading file '/usr/local/bin/awsume'

I'm not too savvy on why this would happen, it almost seems like the script is interpreted in fish instead of bash? If so then maybe using bass to expand the alias isn't the right approach when using fish.

By the way, I tried to do bass source awsume but I can't get it working now.

@Prophecy67
Copy link
Contributor

Hey @c-bandy

I am using the following in a function, which loads on init of the fish shell. I don't know if the autoawsume works.. I usually for the sake of it refresh the session so I am confident that I am working on the correct AWS Profile.

awsume> # Defined in ~/.config/fish/functions/awsume.fish @ line 1

        function awsume
            bass source /Your/User/Directory/Library/Python/3.7/bin/awsume $argv
        end

If you exec awsume without any profile it barfs, but once you put in a profile it does work fine. It's not the cleanest but we as fish-users have to make due :)

@furudean
Copy link
Author

Thanks for your suggestion. I tried this and indeed it works! It however seems to hang when you use awsume profile_name -a, and exiting also does not export the credentials.

Thanks for the workaround! This will keep me happy for now. It would be great to have it work natively though.

@furudean
Copy link
Author

furudean commented May 15, 2020

For anyone else running into this - I ended up rewriting your function. I think this implementation is a bit more portable if your Python isn't in Your/User/Directory/Library/Python/3.7.

function awsume
	bass source (which awsume) $argv
end

@erismaster
Copy link

@c-bandy I am using a very similar function, its been working well for me for a few months now!

@benkeil
Copy link

benkeil commented Jul 10, 2020

Did you also find a solution for autocompletion?

@mbarneyjr
Copy link
Member

mbarneyjr commented Dec 27, 2020

Happy holidays!

Finally getting around to this, we wrote a dedicated fish shell script (in shell_scripts/awsume.fish), since fish has some bash incompatibilities that you were hitting before. We had to work out a custom alias to make the awsume command target the awsume.fish script, so you should no longer use bass with awsume, as using it with the bash script has it's own issues around how it handles subprocesses - autoawsume blocking the shell it should have been spawned from.

When installing awsume, if you have a fish executable, you should see the ~/.config/fish/functions/awsume.fish file be created if it isn't already, and the following added:

alias awsume="source (which awsume.fish)"

Unless you're using pyenv, in which case it'll look like this:

alias awsume="source (pyenv which awsume.fish)"

Support for fish as an option to the --shell flag has also been added to the awsume-configure command. Autocomplete is not yet implemented for fish

This is currently released under awsume==4.5.1a1 (although I'll be pushing updates so install the latest pre-release listed here). I'll keep this in a pre release for a little while until it's tested further (no one here has experience using fish as their primary shell), so please reach out if you find any bugs, it's greatly appreciated!

@Prophecy67
Copy link
Contributor

Hey @mbarneyjr

First of all, great work! Awsume to see this return!

With the pre-release however of 4.5.1a1 and 1a2 I'm getting the following still when doing a list of profiles. Might be PEBCAK:

~ $ awsume -l                                                           10:52:01
Traceback (most recent call last):
  File "/Users/REDACTED/Library/Python/3.8/bin/awsumepy", line 8, in <module>
    sys.exit(main())
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/awsume/awsumepy/main.py", line 29, in main
    run_awsume(sys.argv[1:])
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/awsume/awsumepy/main.py", line 17, in run_awsume
    awsume.run(argument_list)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/awsume/awsumepy/app.py", line 262, in run
    profiles = self.get_profiles(args)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/awsume/awsumepy/app.py", line 107, in get_profiles
    self.plugin_manager.hook.post_collect_aws_profiles(
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/awsume/awsumepy/default_plugins.py", line 299, in post_collect_aws_profiles
    profile_lib.list_profile_data(profiles, arguments.list_profiles == 'more')
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/awsume/awsumepy/lib/profile.py", line 259, in list_profile_data
    print_formatted_data(formatted_profiles)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/awsume/awsumepy/lib/profile.py", line 253, in print_formatted_data
    print('  '.join((val.ljust(width) for val, width in zip(row, widths))))
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/colorama/ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/colorama/ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/colorama/ansitowin32.py", line 190, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "/Users/REDACTED/Library/Python/3.8/lib/python/site-packages/colorama/ansitowin32.py", line 196, in write_plain_text
    self.wrapped.flush()
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <colorama.ansitowin32.StreamWrapper object at 0x10236f340>
BrokenPipeError: [Errno 32] Broken pipe
Listing...

==================================AWS Profiles==================================

@mbarneyjr
Copy link
Member

Sorry for the delays, but Fish shell autocomplete has been implemented in 4.5.1a3, let us know if you hit any other bugs!

@Prophecy67 Looking at the error message, it's a common one I received when trying to use colorama on Windows, which is why it should be disabled on Windows machines by default. However, it looks like you're using a unix like OS such as OS X with your /Users/... path, so I'm not sure why exactly you'd get that error. If it's preventing you from using awsume, you can disable color output with awsume --config set colors false. Do you happen to still be hitting that error? If so, can you explain a bit more about your environment (OS, Python version, shell, how awsume is installed - pipx, pip, pyenv, etc)?

@mbarneyjr
Copy link
Member

I've released 4.5.1 that should support fish shell completely. If you have any issues, please re-open this issue or create a new one, thank you!

@ibqn
Copy link

ibqn commented Nov 24, 2021

Nice, works great, however somehow no alias was created for me automatically for the fish shell.

I have added this file ~/.config/fish/functions/awsume.fish manually, with that content

alias awsume="source (which awsume.fish)"

This is how install messages looked like btw.

$ pipx install awsume                                                                                                                                                                                 
  installed package awsume 4.5.3, Python 3.8.10                                                                                                                                                                    
  These apps are now globally available                                                                                                                                                                            
    - autoawsume                                                                                                                                                                                                   
    - awsume                                                                                                                                                                                                       
    - awsume-autocomplete                                                                                                                                                                                          
    - awsume-configure                                                                                                                                                                                             
    - awsume.bat                                                                                                                                                                                                   
    - awsume.fish                                                                                                                                                                                                  
    - awsume.ps1                                                                                                                                                                                                   
    - awsumepy                                                                                                                                                                                                     
done! ✨ 🌟 ✨        

@Prophecy67
Copy link
Contributor

Hey @ibqn!

This Alias should/will be configured if you run awsume-configure. @mbarneyjr has gracefully provided us with a version that also works with Fish Shell after all!

That should configure everything for you, and no longer need this issue or workaround, especially since it is a closed issue. Hope that solves all of your issues you have with awsume!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants