DEV Community

Cover image for Making my aliased commands in zsh better
2

Making my aliased commands in zsh better

Just read the post about AWS Q Developer CLI update this morning. TL;DR: you can now run prompts from the CLI with a prompt to update files, execute system commands, and more. This opens up some very interesting ways to make my life easier so I can focus on my real priority: enjoying more coffee. Read till the end to see where this is going, and what I'll be building next. ;)

Before we get started with the fun, this is only one of the many capabilities. I was watching my friend Darko use it to create EC2 instances today from a prompt... Follow the instructions in the AWS Docs to install it.

Thinking of ways I want to use it, I know that keeping a README.md file updated is not always the highest priority, so I tried it out with the following prompt to see how past-Cobus did:

Can you update the readme based on the code in this repo. Please maintain the Security and License sections at the bottom of the file exactly as they are.

And off it goes!

Terminal showing output of Amazon Q Developer CLI working through the files to generate the readme file.

I tested it out on the Terraform Samples I worked on last year, and it picked up that I had forgotten to document one of the sample modules I built. The README.md wasn't rewritten from scratch, Q Dev picked up on the format (using a table), and then added a new row for the missing module (you can see the extra row on line 47 in the code block below):

Write to filesystem
β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”
Path: README.md

Replacing:

-  1 ## Terraform samples
-  2 
-  3 Collection of examples of how to use Terraform with AWS.
-  4 
-  5 List of modules:
-  6 
-  7 | Module | Description|
-  8 |-|-|
-  9 |[bootstrap-aws-account](./modules/bootstrap-aws-account/)|Helps bootstrap a new AWS account to use Terraform by creating the resources needed to store the state file.|
- 10 |[bootstrap-cicd-aws-codebuild](./modules/bootstrap-cicd-aws-codebuild/)|Sets up a CI/CD pipeline for Terraform in a GitHub repo, with workflows to add the plan as a comment on pull requests, and apply changes when a PR is merged using AWS CodeBuild.|
- 11 |[bootstrap-cicd-github-actions](./modules/bootstrap-cicd-github-actions/)|Sets up a CI/CD pipeline for Terraform in a GitHub repo, with workflows to add the plan as a comment on pull requests, and apply changes when a PR is merged using GitHub Actions.|
- 12 |[bootstrap-cloudtrail](./modules/bootstrap-cloudtrail/)|Sets up a basic AWS CloudTrail configuration for the account.|
- 13 |[aws-billing-budget-notification](./modules/aws-billing-budget-notification/)|Sets up an AWS Budget with an email alert.|
- 14 
- 15 ## Security
- 16 
- 17 See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
- 18 
- 19 ## License
- 20 
- 21 This library is licensed under the MIT-0 License. See the LICENSE file.

With:

+  1 ## Terraform samples
+  2 
+  3 Collection of examples of how to use Terraform with AWS.
+  4 
+  5 List of modules:
+  6 
+  7 | Module | Description|
+  8 |-|-|
+  9 |[bootstrap-aws-account](./modules/bootstrap-aws-account/)|Helps bootstrap a new AWS account to use Terraform by creating the resources needed to store the state file.|
+ 10 |[bootstrap-cicd-aws-codebuild](./modules/bootstrap-cicd-aws-codebuild/)|Sets up a CI/CD pipeline for Terraform in a GitHub repo, with workflows to add the plan as a comment on pull requests, and apply changes when a PR is merged using AWS CodeBuild.|
+ 11 |[bootstrap-cicd-github-actions](./modules/bootstrap-cicd-github-actions/)|Sets up a CI/CD pipeline for Terraform in a GitHub repo, with workflows to add the plan as a comment on pull requests, and apply changes when a PR is merged using GitHub Actions.|
+ 12 |[bootstrap-cloudtrail](./modules/bootstrap-cloudtrail/)|Sets up a basic AWS CloudTrail configuration for the account.|
+ 13 |[aws-billing-budget-notification](./modules/aws-billing-budget-notification/)|Sets up an AWS Budget with an email alert.|
+ 14 |[temp-ec2-instance](./modules/temp-ec2-instance/)|Creates a temporary EC2 instance with Terraform pre-installed for bootstrapping purposes. Includes VPC, security group, and IAM role configuration.|
+ 15 
+ 16 Examples:
+ 17 
+ 18 | Example | Description|
+ 19 |-|-|
+ 20 |[bootstrap-new-aws-account](./examples/bootstrap-new-aws-account/)|Example showing how to bootstrap a new AWS account with the necessary Terraform infrastructure.|
+ 21 
+ 22 ## Security
+ 23 
+ 24 See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
+ 25 
+ 26 ## License
+ 27 
+ 28 This library is licensed under the MIT-0 License. See the LICENSE file.

Enter y to run this tool, otherwise continue chatting.
Enter fullscreen mode Exit fullscreen mode

This will come in handy quite often. Along with some other use-cases. It will however get very tiring to constantly type out this prompt...

Dotfiles

First a confession: I've know about dotfiles for a long time, but I just created my personal repo 5 minutes ago... I had a quick look at options on how to alias commands that I would need, and the following seems like an ok approach, but please let me know in the comments how I can make this better. Step one is to create a folder where you can store some bash scripts. I want to be able to use these to define the aliases that I can just call later by adding them to ~/.bashrc or ~/.zshrc. I'm going to group my aliases together in a script per topic or tool, e.g. I'll use q-helpers.sh for Q Dev, and likely git-helpers.sh for some git commands.

Inside q-helpers.sh I have the following:

alias q-readme='q chat "Can you update the readme based on the code in this repo. Please maintain the Security and License sections at the bottom of the file exactly as they are. If it makes sense, also include a Mermaid diagram in the Readme.'

alias q-add-license='q chat "Can you please add the SPDX line to all source code files with the appropriate string for the license based on which one has been defined?"
Enter fullscreen mode Exit fullscreen mode

The code block makes it easy to copy/paste, but hard to read, so here are the 2 lines on their own - note how the command is wrapped with a single quote ' and the prompt with double quotes ".

alias add q-readme='q chat "Can you update the readme based on the code in this repo. Please maintain the Security and License sections at the bottom of the file exactly as they are. If it makes sense, also include a Mermaid diagram in the Readme."

alias q-add-license='q chat "Can you please add the SPDX line to all source code files with the appropriate string for the license based on which one has been defined?"

Then I need to make them executable by running chmod +x q-helpers.sh. The last step now is to add them to ~/.zshrc (I use zsh with oh-my-zsh):

# Source all files in dotfiles directory
for file in ~/dotfiles/*.sh; do
    [ -r "$file" ] && source "$file"
    echo "Dotfiles loaded."
done
Enter fullscreen mode Exit fullscreen mode

Now all I need to do is run source ~/.zshrc, and I can call q-readme and q-add-license from anywhere. Thinking about it, I could probably combine a number of instructions in a single prompt to cover a lot of common scenarios...

And let's not forget about setting up some git hooks...

I'd love to hear what commands you add to your dotfiles, and if this will replace any existing ones, let me know in the comments below!

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay