Windows Terminal Tips, Tricks, and Productivity Hacks Optimize your command-line usage and development processes with pro-level techniques Will Fuqua BIRMINGHAM—MUMBAI Windows Terminal Tips, Tricks, and Productivity Hacks Copyright © 2021 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Associate Group Product Manager: Pavan Ramchandani Publishing Product Manager: Kaustubh Manglurkar Senior Editor: Sofi Rogers Content Development Editor: Aamir Ahmed Technical Editor: Saurabh Kadave Copy Editor: Safis Editing Project Coordinator: Ajesh Devavaram Proofreader: Safis Editing Indexer: Tejal Daruwale Soni Production Designer: Jyoti Chauhan First published: April 2021 Production reference: 1280421 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-80020-756-1 www.packt.com To my kind and loving wife, Koi, who showed the utmost patience during the writing of this book. – Will Foreword Whether you are building a web app or working in the cloud, the command line has always been an integral tool for software developers and IT admins alike. For many years, the Windows command-line experience lagged behind that of Unix-based systems. Even simple things, such as selecting and copying text, required you to jump through hoops. In the 2010s, Microsoft began to improve the command-line experience with Windows Subsystem for Linux (WSL), PowerShell improvements, and a command-line interface. WSL provided a first-party solution to running a Linux environment on your Windows device. PowerShell continued to receive incremental improvements to surpass the usability of CMD. The Windows Package Manager released a command-line interface as a first-party solution to install software on your machine. Even with all of these command-line tools, Windows lacked a solid terminal to host them in and Microsoft quickly realized how difficult it was to make improvements without breaking certain legacy behavior. In 2019, Microsoft introduced the Windows Terminal, a new unified experience for hosting command-line tools. To make things better, Windows Terminal was open sourced alongside the in-box console host experience with which Windows command-line users were already familiar. It put customizability first, with a profile-based settings model and key bindings. Furthermore, a rapid release cycle helped to collect and address user feedback swiftly. This book does a fantastic job of teaching you how to set up Windows Terminal and make it your own. You will learn how to create and manage your profiles to get the most out of your terminal and customize your actions and key bindings to be an effective user. Even better, you will learn how to get started using the terminal more often in day-to-day activities. The author teaches you how to use PowerShell and bash and how to customize them for your needs. The book will also teach you how to apply these tools to build apps, manage remote systems, and interact with the cloud. Carlos Zamora Software Engineer on Windows Terminal at Microsoft Contributors About the author Will Fuqua has been developing software professionally for 12 years using a wide range of technologies. Initially based in the United States as a software consultant, he developed production systems for companies in the healthcare and finance industries, among many others. He then moved abroad and is now the Head of Engineering for an online travel agency, where he leads a high-powered technology team out of Bangkok, Thailand. You can find him online at https://fuqua.io/. About the reviewers Chester Liu is an open source enthusiast living in China. He got his first job as an iOS developer in 2016, after he graduated from college. During his professional career, he has worked on various platforms and in different areas. He is a long-time member of the GitHub community and has been contributing to the Windows Terminal project since 2019, after the project was open sourced by Microsoft. His contribution to the project falls into different areas, including, but not limited to, rendering, performance, and VT support. I'd like to thank the core team of the Console subsystem at Microsoft, who I'm glad to have made acquaintance with through our collaboration in the Windows Terminal project. They went through the trouble of convincing the management to open source a deep OS component of the Windows OS itself, just to bring the community a thrilling console experience. At the end of the day, the members of the console team are the ones who dived into the legacy console source code and have been trying to improve the console experience on Windows for the past several years. Dustin L. Howett, the tech leader of the console team, is one of the coolest tech leaders I know, and I'm truly honored to be a member of his "external" team. Daniel Engberg is a principal consultant and partner at Agdiwo, an IT services company based in Gothenburg, Sweden. Daniel's focus is Microsoft enterprise client management, including Microsoft Endpoint Configuration Manager (formerly System Center Configuration Manager), Windows 10, and PowerShell. Daniel has been writing on his blog since 2010 and is active on Twitter. Table of Contents Preface Section 1: Introducing the New Windows Terminal 1 Getting started with the new Windows Terminal Technical requirements 4 Open source development 10 Why a new terminal? 4 Installing Windows Terminal 11 The modern foundations of Launching Windows Terminal 12 Windows Terminal 5 Summary 14 A Modern UI 6 Further reading 15 Flexible JSON-based customization 9 2 Learning the Windows Terminal UI Technical requirements 18 Using the command palette 24 Using the terminal tabs 18 Keyboard shortcuts review 26 Editing tab title appearance 20 Summary 28 Further reading 28 Using terminal panes 20 Managing terminal output 22 ii Table of Contents 3 Configuring an Ubuntu Linux profile Technical requirements 30 Installing Linux applications: Why use the Windows nginx 34 Subsystem for Linux? 30 Starting nginx 35 Installing Ubuntu Linux 31 Bidirectional access in Windows Step 1: Install WSL2 32 and Ubuntu 36 Step 2: Install Ubuntu 32 Summary 38 Launching Linux 33 Section 2: Configuring your Windows Terminal and its shells 4 Customizing your Windows Terminal settings Technical requirements 42 Custom command-line profiles 49 Introducing the settings.json file 42 Git Bash shell 49 Recovering from bad settings 44 SSH shell 50 C# interactive shell 51 The settings file structure 44 Node.js interactive shell 52 Useful Global Settings 46 Vim terminal shell 53 Useful profile settings 47 Summary 54 5 Changing your Windows Terminal appearance Technical requirements 56 Background images and Terminal color schemes 56 translucency 60 Customizing PowerShell with Built-in color schemes 56 posh-git, oh-my-posh, and Community-driven color schemes 58 PSReadLine 63 Writing your own theme 59 Oh-my-posh version 2 64 Table of Contents iii Oh-my-posh version 3 65 WSL2 customization with oh- Changing the prompt without oh-my- my-zsh 70 posh 66 Command Prompt Changing command colors with customization 71 PSReadline 68 Summary 74 6 Setting up keyboard shortcuts Technical requirements 76 Configuring custom terminal Overview of the keyboard layouts with "wt" 80 shortcut system 76 Additional uses of 'wt' 82 Building custom commands Summary 84 with "sendInput" 78 7 Hidden Windows Terminal Actions Technical requirements 86 setColorScheme 92 Discovering unbound actions 86 toggleShaderEffects 92 Using actions for focus Using actions for tab management 88 manipulation 93 togglePaneZoom 89 Closing multiple tabs at once 93 toggleAlwaysOnTop 90 Changing tab colors 94 toggleFocusMode 91 Summary 94 Using actions for visual effects 91 8 Tips for using PowerShell like a Pro Technical requirements 96 The ii command 100 Installing PowerShell Core 96 History navigation with h and r 100 Pipelines and $_ 101 Using built-in commands and Custom Profile Aliases and Functions 102 aliases 98 Automatic Variable: $^ and $$ 98 Configuring PSReadLine in cd - and cd + 99 PowerShell Core 103