VOOZH about

URL: https://dzone.com/articles/elevate-your-terminal-game

⇱ Elevate Your Terminal Game


Related

  1. DZone
  2. Culture and Methodologies
  3. Career Development
  4. Elevate Your Terminal Game: Hacks for a Productive Workspace

Elevate Your Terminal Game: Hacks for a Productive Workspace

This guide explores ways to enhance productivity and personalize your terminal for efficient workflow, all aimed at saving time and keystrokes.

Likes
Comment
Save
6.9K Views

Join the DZone community and get the full member experience.

Join For Free

In the realm of productivity, every efficiency gained counts. For many, the terminal serves as the central hub for navigating the digital landscape. Whether you're a seasoned developer, a system administrator, or simply someone who spends a lot of time working in the command line, customizing your terminal can transform it from a basic tool into a personalized powerhouse. In this guide, we'll explore various ways you can hack your terminal to enhance your workflow, boost productivity, and create a workspace tailored to your needs. Most of the stuff will revolve around modifying your bashrc/zshrc config.

Enhance the Look With Powerlevel10k

The aesthetic appeal of your terminal plays a significant role in your overall experience. Powerlevel10k is one of the coolest themes you can install in your zsh terminal. It transforms your terminal from a basic interface into a sleek, informative, and visually captivating display, providing a significant upgrade in both aesthetics and functionality.

Extensions and Plugins: Supercharge Your Shell

Two indispensable plugins for the Zsh shell are zsh-autosuggestions and zsh-syntax-highlighting. These tools greatly enhance the functionality and user experience of the Zsh shell.

  • Zsh-autosuggestions: Intelligently suggests completions for commands as you type, based on your command history. This feature not only saves time but also helps prevent typos and errors by offering contextually relevant suggestions.
  • Zsh-syntax-highlighting: Provides visual feedback on the validity of your commands by highlighting syntax errors, invalid options, and other potential issues in real time. By catching errors early on, it streamlines the command-line experience, reducing the likelihood of errors and enhancing overall productivity.

Command-Line Tools and Utilities: Your Efficiency Boosters

Learn text processing command-line tools like sed and jq to cut down your time significantly. jq, for example, is a powerful tool for parsing and manipulating JSON data effortlessly. Its concise syntax simplifies tasks like extracting fields, filtering data, and formatting output. Widely embraced by developers, sysadmins, and data engineers, jq streamlines JSON processing, boosting productivity in scripts, pipelines, and automation workflows.

Aliases and Functions: Your Time-Saving Techniques

Aliases and functions are indispensable tools for saving time and keystrokes in the terminal. Utilizing frameworks like oh my zsh, you can easily have aliases for frequently used commands or sequences, making your life easier. Functions allow you to combine multiple commands into a single, easily executable line, further streamlining your workflow.

Shell Scripts: Automate Your Tasks

Shell scripts are invaluable tools for streamlining and automating tasks, significantly enhancing the efficiency and convenience of terminal usage. By writing shell scripts, users can automate repetitive tasks, such as file manipulation, data processing, and system maintenance, saving time and effort in the long run.

Example: A Day in the Life of a Developer

Being a software developer, I’ll go through my day-to-day activities with my terminal and how I do it differently with the help of all these points I made. From creating branches and pushing code to triggering builds on Jenkins and deploying images onto clusters, every step is optimized for efficiency and convenience.

Customizing Git Workflow With Aliases and Functions

One of my personal favorites is leveraging aliases and functions to streamline Git workflows. For instance, instead of typing out lengthy commands like git push origin branchname, I've created an alias ggp using oh my zsh, allowing me to accomplish the same task with just ggp.

Shell
function gitpush() {
 gaa
 gcmsg "$*"
 ggp
}
# function call
# gitpush Add a meaningfull commit message here


Additionally, I've created a function called gitpush that uses oh-my-zsh aliases and combines adding, committing, and pushing changes in a single line, saving valuable time and keystrokes.

Automating Jenkins Builds With Custom Functions

To trigger Jenkins builds with ease, I've crafted a custom function called jenkins-build().

Shell
function jenkins-build(){
 curl -X POST https://your_jenkins_server.com/job/your_job/build --user username:apikey \
 --data-urlencode json='{"parameter": [{"name":"BRANCH_NAME", "value":"'"$1"'"}]}'
}


This function utilizes the Jenkins API to initiate a build by passing the branch name as a parameter. Now, starting a build is as simple as typing jenkins-build my_branch_name, eliminating the need for manual intervention and speeding up the development process.

Deploying Images Onto Clusters With Shell Scripts and Aliases

Deploying images onto clusters involves several steps, including logging in, fetching relevant data, and updating configurations. To streamline this process, I've created a shell script that performs these tasks efficiently. I created aliases to log in to different openshift clusters as I work with more than 3 clusters.

Shell
alias oc-dev='oc login dev-server.com -u username -p password -n namespace'
alias oc-stage='oc login stage-server.com -u username -p password -n namespace'


I also wrote a shell script that edits the deployment file to change the image deployed on the cluster, which, when run, would replace the image tag for a service with the one specified.

Shell
ocimage() {
 oc get deployment your_service -o yaml > your_service.yaml
 imageTag="$1"
 found=false # Flag to track if image: is found
 > your_service-apply.yaml # Create a file to replace the existing deployment
 # Read the input file line by line
 while IFS= read -r line; do
 if [[ $line == *"image:"* && $found == false ]]; then
 line=$(echo "$line" | sed "s|image: artifactory_url:[^ ]*|image: artifactory_url:${imageTag}|g")
 found=true # Set the flag to true
 fi
 echo "$line" >> your_service-apply.yaml # Write the line to the temporary file
 done < your_service.yaml
	if [[ $found == false ]]; then
 echo image not changed
 rm your_service.yaml
 rm your_service-apply.yaml
 else
 echo image changed to $imageTag
 oc apply -f your_service-apply.yaml
 rm your_service.yaml
 rm your_service-apply.yaml
 
 fi
}


By leveraging aliases like oc-dev for logging in and ocimg for deploying images, I can execute complex tasks with minimal effort, allowing me to focus on developing and testing my code.

We're eager to discover the inventive ideas and clever shortcuts you've integrated into your workflow! Share your insights in the comments below to inspire and empower others in our community. Whether it's a time-saving script, a handy alias, or a nifty command sequence, your contributions can unlock new possibilities and streamline terminal usage for everyone. Let's collaborate and unleash the full potential of our collective expertise!

shell Git Productivity career

Opinions expressed by DZone contributors are their own.

Related

  • Maximizing Developer Efficiency and Productivity in 2024: A Personal Toolkit
  • Code Review That Matters: Tips and Best Practices
  • SSD vs. HDD: How the Choice of Storage Affects Developer Workflows
  • Outsourced Software Development Team: Six Key Practices for Efficiency

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

Let's be friends: