aboutsummaryrefslogtreecommitdiffstats
path: root/src/_mssh
diff options
context:
space:
mode:
authorHyeon Kim <simnalamburt@gmail.com>2020-12-30 16:51:20 +0900
committerHyeon Kim <simnalamburt@gmail.com>2020-12-30 17:02:50 +0900
commit43a6b813082bce92e25569cb53cd840e3878544e (patch)
treeafc0d31ce1357006532606c0871b16272d452ecf /src/_mssh
parentMerge pull request #711 from kanashimia/master (diff)
downloadzsh-completions-43a6b813082bce92e25569cb53cd840e3878544e.tar
zsh-completions-43a6b813082bce92e25569cb53cd840e3878544e.tar.gz
zsh-completions-43a6b813082bce92e25569cb53cd840e3878544e.tar.bz2
zsh-completions-43a6b813082bce92e25569cb53cd840e3878544e.tar.lz
zsh-completions-43a6b813082bce92e25569cb53cd840e3878544e.tar.xz
zsh-completions-43a6b813082bce92e25569cb53cd840e3878544e.tar.zst
zsh-completions-43a6b813082bce92e25569cb53cd840e3878544e.zip
Add 'mssh' completion
mssh is a Python client for accessing EC2 instances via AWS EC2 Instance Connect. References: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html#ec2-instance-connect-connecting-ec2-cli https://github.com/aws/aws-ec2-instance-connect-cli https://pypi.org/project/ec2instanceconnectcli/
Diffstat (limited to 'src/_mssh')
-rw-r--r--src/_mssh52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/_mssh b/src/_mssh
new file mode 100644
index 0000000..ee6b763
--- /dev/null
+++ b/src/_mssh
@@ -0,0 +1,52 @@
+#compdef mssh
+
+# mssh is a Python client for accessing EC2 instances via AWS EC2 Instance
+# Connect.
+#
+# References:
+# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html#ec2-instance-connect-connecting-ec2-cli
+# https://github.com/aws/aws-ec2-instance-connect-cli
+# https://pypi.org/project/ec2instanceconnectcli/
+
+# Define function only when it doesn't exist
+(( $+functions[_mssh_cache_policy] )) || _mssh_cache_policy() {
+ # Cache invalidates after 30 seconds
+ #
+ # Reference:
+ # http://zsh.sourceforge.net/Doc/Release/Expansion.html#index-globbing_002c-qualifiers
+ local -a oldp
+ oldp=( "$1"(ms+30) )
+ (( $#oldp ))
+}
+
+# Unless user explicitly turned off caching, enable caching just for this context
+local existing_setting
+zstyle -s ":completion:${curcontext}:" use-cache existing_setting
+if [[ -z "${existing_setting}" ]]; then
+ zstyle ":completion:${curcontext}:" use-cache on
+fi
+
+# Update cache policy only when there was no existing policy
+local existing_policy
+zstyle -s ":completion:${curcontext}:" cache-policy existing_policy
+if [[ -z "${existing_policy}" ]]; then
+ zstyle ":completion:${curcontext}:" cache-policy _mssh_cache_policy
+fi
+
+local -a instances
+if _cache_invalid mssh_instances || ! _retrieve_cache mssh_instances; then
+ # Cache is invalid or caching feature is disabled
+ IFS=$'\n\t' instances=($(
+ aws ec2 describe-instances \
+ --query 'Reservations[].Instances[] | [?State.Name == `running`].join(`:`, [InstanceId, Tags[?Key == `Name`].Value | [0]])' \
+ --output text
+ ))
+
+ _store_cache mssh_instances instances
+fi
+
+_describe 'command' instances
+
+# Reference:
+# http://zsh.sourceforge.net/Doc/Release/Completion-System.html
+# https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org