Archive

Posts Tagged ‘zsh’

Start Midnight Commander with a button press

March 9, 2025 Leave a comment

Problem

I use Midnight Commander all the time and I type “mc” at least 50x per day. Could I assign it to a key on my keyboard? And in more general: when I press a specific key on my keyboard, can I execute a custom command in my shell?

Solution

I use WezTerm as my terminal emulator and ZSH as my shell. I never use the ScrollLock key on my keyboard, so it was a perfect candidate. The idea is the following: when I press ScrollLock, a custom escape sequence will be generated by WezTerm. It functions like an event. My ZSH shell will catch this “event” and perform an action.

First, add this to your ~/.config/wezterm/wezterm.lua file:

local wezterm = require 'wezterm'

return {
    keys = {
        { key = "ScrollLock", mods = "NONE", action = wezterm.action { SendString = "\x1b[ScrollLock]" } },
    },
}

Then, add the following line to your ~/.zshrc file:

bindkey -s '\e[ScrollLock]' 'mc\n'

Open a new terminal and it should work.

QuickJump: bookmark your directories and switch between them easily

June 30, 2019 Leave a comment

I made a little project that facilitates jumping between directories in the command line. You can find it here: https://github.com/jabbalaci/quickjump . Visit the GitHub page for more info.

Demo

Categories: python, shell Tags: , , , ,

[shell] How to tell your distro version?

November 28, 2018 Leave a comment

Problem
I use two different Linux distros, Ubuntu and Manjaro. Both of them are great. My shell resource files (previously .bashrc, now .zshrc) are shared via Dropbox. However, sometimes I would like to differentiate my Ubuntu and Manjaro settings, within the same resource file. How to do that?

Solution
Here is what I use:

# DESKTOP_SESSION is "ubuntu" (for Ubuntu) or "xfce" (for Manjaro)
if [[ "$DESKTOP_SESSION" == "ubuntu" ]]; then
  alias files='dpkg-query -L'
else
  alias files='pacman -Ql'
fi 

Older solution
Before finding the environment variable DESKTOP_SESSION, I used this:

# return "ubuntu", "manjaro" (without quotes)
get_distro_name() {
  cat /etc/os-release | grep "^ID=" | cut -d= -f2
}

# usage:
# if [[ $(get_distro_name) == "ubuntu" ]]; then
#   alias files='dpkg-query -L'    # ubuntu
# else
#   alias files='pacman -Ql'       # manjaro
# fi
Categories: shell Tags: , , , , ,
Design a site like this with WordPress.com
Get started