A few things you could use to improve your software development experience
In which I give a few pointers to things I use regularly (meaning: on a daily basis) and that generally save time or makes your life easier.
git
Mastery of git is more than essential. It’s better to start using the command line (with the included helpersgitk
and git gui
) rather than a full GUI in order to (really) learn what it does. As a heavy emacs user I use magit and got so used to it that it is sometimes the sole reason I have an emacs client running.
Whichever client you use, you should be super comfortable doing these very basic actions:
- cloning a repository
- creating/switching branches
- staging and commiting code
- pushing commits
- merging or rebasing a remote branch
- create short aliases for often use commands (eg
co
forcheckout
)
More arcane functionalities you could use on a daily basis:
- interactive rebase on the latest commits (
git rebase -i HEAD~5
): move commits, squash useless commits, edit the commit message - set the upstream of a branch to
origin/master
so you can easily pull the latest changes - use the stash when there is a conflict during a branch change/pull
- use the staging area to “save” your work in progress
- stage and commit hunks of code and not the whole diff in a file
- Add additional missing things to your latest commit with
git commit --amend --no-edit
- safely force push to fixup things or just update your pending pull request:
git push --force-with-lease
- use
pull --rebase
(will rebase your work on top of the remote branch) and rebase autostash (will stash all your pending changes, rebase then re-apply your pending work)
tmux
Instead of learning the peculiarities of a fancy terminal GUI with tabs and split screen, use tmux.
The first good reason is that it will work the same way anywhere (OSX, linux, cygwin windows…). The second good reason is that when you are connected to a remote host or inside a docker container you’ll be happy to know the commands fluently.
Commands
C-B w
shows the windows list and allow quick navigation with a freaking previewC-B l
go to the latest tab. Useful when you need to constantly switch between the same two tabsC-B z
“zoom” the current window. Super useful when you have a split and need to see a large file or log. Type the same again to unzoom.C-B [
enter copy mode, the useful thing here is the search forwardC-s
and search backwardC-r
functionality. Leave withq
:setw synchronize-panes
type the same things in multiple panes (eg: you have three ssh sessions and want to do exactly the same things on the three host quickly)
Config
set-window-option -g automatic-rename on
: so tabs are named after the current directoryset-option -g set-titles on
: so your fancy terminal title means somethingset -g mouse on
: because resizing panes or scrolling using the keyboard is just painful. And sometimes it is way easier to click on a window to activate it.
Addons
- tpm: plugin manager
- resurrect: save and restore sessions (your tabs, splits and their content)
- continuum: automatically saves your sessions so you don’t have to
docker
Apart from your IDE, your text editor of choice, maybe a compiler and a few basic tools you should be able to work without installing anything. If you have to setup nginx or mysql locally you could probably use docker instead.
Command line docker with more than just a few options is painful. So, use docker-compose for anything complex (eg: you need to mount 3 directories and 2 files, open 2 port, set 4 environment variables, change the default command). Things will be much more clear and easily reusable.
Interesting usage during your daily work is the ability to try different version of a software painlessly.
For instance, to try build your java project in java 8 and 10 this would work:
$ docker run --rm -v "$(pwd):/data" -w "/data" -u $UID openjdk:8 ./gradlew build -x check
then:
$ docker run --rm -v "$(pwd):/data" -w "/data" -u $UID openjdk:10 ./gradlew build -x check
Here you execute a command in a specific java environment, sharing your current working directory and creating files using your current user UID (so you won’t have root
owned files created)
If you want a web based ui to see what containers are running, what images do you have and whatnot, you can use portainer.io, and yes, you can run it with docker:
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer --no-auth
visit http://127.0.0.1:9000, choose “local environment” and you are good to go
Basic tools
less
Builtin command to paginate files. Among the thing you can do:
G
: go to the end of the file42G
: go to line 42/
: search a stringF
: go to the end of the file and starts pulling the file for changes. Think of it as atail -f
you can interrupt and search anytimeq
: quit
rg
a better grep
, taking into account .gitignore
file among other things like programming language based file extensions filtering (eg: filter for C language considers both .c
and .h
files).
fd
An easier to use find
.
ncdu
An interactive shell based and fasterdu
command
perl for recursive find and replace
The easier/faster way I found to find and replace a regex in multiple files is to use perl:
perl -p -i.bkp -e 's/to replace/new text/g' **/*
This is extremely fast and with the previous example will backup all modified files with a .bkp
extension (if you don’t want that, just remove the .bkp
in the command. Or name it differently if you want).
lnav
Powerful and easy to use log viewer. Can display multiple log files in the same screen, syntax coloring, quick error navigation.
zsh
For your daily work, drop bash and install a decent shell. Meaning one with bells and whistles.
oh-my-zsh
Vanilla zsh is painful to configure. oh-my-zsh fixes this.
I have the following plugins enabled:
git
: autocompletes git commandssafe-paste
: write a return character in your shell when you paste something with an EOL character in it instead of executing the command right away.docker
: docker auto completionzsh-autosuggestions
: show you a possible completion of the current line you are typing based on your historyk
:ls
alternative, shows git status of files and uses informative colorscommand-no-found
: shows you how to install the required missing package when you type a not found commandtmux
: aliases and run helpers for tmuxautojump
: sources the autojump configuraton file (see after)
autojump
Keeps a weighted history of your visited paths and allows you to quickly go back anywhere by typing j
and a few letters of the directory you want to visit.
fzf
A better way to navigate your shell history, removes duplicates (with setopt HIST_IGNORE_ALL_DUPS
) and fuzzy finds words.