IntroducingSupercharge Your Zsh Shell with Cross-Device History and Autosuggestions Using histdb and zsh-autosuggestions

Introduction

For many developers and system administrators, the zsh (Z Shell) has become a powerful alternative to more traditional Unix shells, like Bash. It offers a wide range of customizations, plugins, and enhancements that make it an attractive choice for many power users. Two features that can significantly improve your command line experience are the ability to share your shell history across several devices and to have smart autosuggestions based on that history.

In this post, we'll explore how to set up these features using zsh-histdb and zsh-autosuggestions plugins.

Step 1: Installing

The first step is to install the zsh-histdb plugin, which replaces the default Zsh command history file with a SQLite database. This database not only makes it possible to retrieve and search your history across devices, but also offers performance improvements when dealing with large history files. To install zsh-histdb, follow the instructions below:

  1. Clone the
  1. Add the following line to your
  1. Restart your Zsh shell by typing

Step 2: Setting up a remote SQLite database

The next step is to create a remote SQLite database on a server you have access to, which will store your Zsh history. This can be any remote server that you have SSH access to and supports SQLite.

  1. SSH into your server and create the SQLite database:
  1. Make sure your local machine has access to your SQLite database file. One way to achieve this is by mounting the remote directory containing the database via
  1. Create a local mount point and mount the remote directory:
  1. Modify your
  1. Restart your Zsh shell or open a new terminal, and your Zsh history should now be stored on the remote server, available across all devices that share the same database.

Step 3: Installing zsh-autosuggestions

The zsh-autosuggestions plugin will offer smart auto-completion based on your command history. To install it, follow these steps:

  1. Clone the
  1. Add the following line to your
  1. Restart your Zsh shell or open a new terminal. You should now see autosuggestions based on your command history as you type.

Conclusion

By combining the power of zsh-histdb and zsh-autosuggestions, you can manage a more robust and efficient shell history that syncs across devices, along with context-aware autosuggestions - significantly improving your command line experience.

git clone <https://github.com/larkery/zsh-histdb.git> ~/.zsh-histdb
source ~/.zsh-histdb/zsh-histdb.zsh
sqlite3 ~/zsh_history.db "CREATE TABLE IF NOT EXISTS history (start_time INTEGER PRIMARY KEY, duration INTEGER, exit_code INTEGER, command TEXT, argc INTEGER);"

This command creates a file called zsh_history.db in your server's home directory with the schema required by zsh-histdb.

For Debian/Ubuntu:

sudo apt-get install sshfs

For macOS:

brew install sshfs
mkdir ~/remote-zsh-history
sshfs user@yourserver.com:~/ ~/remote-zsh-history

Make sure to replace "user" with your server's username and "yourserver.com" with your server's address.

export HISTDB_FILE=~/remote-zsh-history/zsh_history.db
git clone <https://github.com/zsh-users/zsh-autosuggestions> ~/.zsh-autosuggestions
source ~/.zsh-autosuggestions/zsh-autosuggestions.zsh