Giter VIP home page Giter VIP logo

q's Introduction

q - registers for your bash and zsh shell

q implements vim like macro registers in your bash and zsh shell!

asciicast

Dynamic Terminal Aliases and Bookmarks On The Go!

Maintainers

๐Ÿ”ธ Cal Martin - Initial implemenation

๐Ÿ”ธ Oisin Johnston - Reconfigurable key bindings :)

Installation

Bash

Manual

Download q.sh to somewhere, and place this line in your .bashrc:

source /path/to/q.sh

ZSH

Antigen

Simply place this line in your .antigenrc:

antigen bundle cal2195/q

NB: if you use zsh-users/zsh-syntax-highlighting, make sure you place antigen bundle cal2195/q below it! :)

Manual

Download q.plugin.zsh to somewhere and place this line in your .zshrc:

source /path/to/q.plugin.zsh

Usage

q commands start with the prefix Q for setting registers, q for executing registers, and U for unsetting registers.

Register names can be any alphanumeric string! Command that already exist in your $PATH take priority:

> Qutebrowser
Sorry, "qutebrowser" already exists in your $PATH! :(

Saving directories

To set a register, navigate to the directory and use the command Q:

> cd ~/fyp/experiments
> Qfe
Register fe set to /home/cal/fyp/experiments

To then cd to that directory, just use q:

> qfe
cd /home/cal/fyp/experiments

Saving commands

To save a command to a register, just add it after the register:

> Qi3c vim ~/.config/i3/config
Register i3c set to vim ~/.config/i3/config

Then you can call up vim using q:

> qi3c
vim ~/.config/i3/config

You can also add arguments!

> Qv vim
Register v set to vim
> qv .zsh/alias.zsh
vim .zsh/alias.zsh

Useful for longer commands:

> Qy yaourt -Syyu
Register y set to yaourt -Syyu
> qy
yaourt -Syyu
:: Synchronising package databases...
...

Listing register contents

To see what registers you have set and their contents, just type q:

> q
q - registers for zsh

Usage: q[register] [args]
       Q[register] [command]
       U[register]

Setting Registers:
 Q[register]                     Set register [register] to current directory
 Q[register] [command]           Set register [register] to [command]

Unsetting Registers:
 U[register]                     Unset register [register]

Running Registers:
 q[register]                     Run command or cd to directory in register [register]
 q[register] [args]              Run command in register [register] with [args]

Registers:
 c: cd /home/cal/.config
 f: cd /home/cal/data/college/fyp
 g: cd /home/cal/data/git
 x: cd /home/cal/data/college/fyp/experiments

Unsetting Registers

To unset a register, simply use the U command:

> Uh
Unset register h.

Setting Custom Commands

To change the default commands (Q,q,U) to something else just set three variables in .zshrc/.bashrc before sourcing the script:

Q_SET='<new_set_command>'
Q_RUN='<new_run_command>'
Q_UNSET='<new_unset_command>'

Usage Help

q - registers for zsh

Usage: q[register] [args]
       Q[register] [command]
       U[register]

Setting Registers:
 Q[register]                     Set register [register] to current directory
 Q[register] [command]           Set register [register] to [command]

Unsetting Registers:
 U[register]                     Unset register [register]

Running Registers:
 q[register]                     Run command or cd to directory in register [register]
 q[register] [args]              Run command in register [register] with [args]

Registers:
 c: cd /home/cal/.config
 f: cd /home/cal/data/college/fyp
 g: cd /home/cal/data/git
 x: cd /home/cal/data/college/fyp/experiments

q's People

Contributors

cal2195 avatar dajuice avatar taigrr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

q's Issues

Fix `Q_โ€ฆ` variables support

q conflicts with https://github.com/harelba/q
Changing the Q_{SET,RUN,UNSET} variables works only partially. There is still a messages that says q is already a command in your \$PATH! : when invoking Q_SET command. Here's my patch:

From 6c0845fbbff8430934d0c488e0ffce4fb8cb40d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrzej=20Jagie=C5=82o?= <[email protected]>
Date: Sat, 26 Aug 2023 18:06:05 +0200
Subject: [PATCH 1/1] fix: replace hardcoded `q` with `${Q_RUN}`

---
 q.plugin.zsh | 6 +++---
 q.sh         | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/q.plugin.zsh b/q.plugin.zsh
index 195f0c8..af24f5e 100644
--- a/q.plugin.zsh
+++ b/q.plugin.zsh
@@ -55,8 +55,8 @@ q-accept-line() {
         fi
 
         # Check if trying to set to an existing command
-        if type "q${MATCH:1}" > /dev/null; then
-            echo "\nSorry, \"q${MATCH:1}\" is already a commamessagesnd in your \$PATH! :("
+        if type "${Q_RUN}${MATCH:1}" > /dev/null; then
+            echo "\nSorry, \"${Q_RUN}${MATCH:1}\" is already a command in your \$PATH! :("
             BUFFER=""
             zle .accept-line
             return
@@ -68,7 +68,7 @@ q-accept-line() {
 
         # If called without register, show help
         if [[ $REG == "" ]]; then
-            echo "\nq - registers for zsh"
+            echo "\n${Q_RUN} - registers for zsh"
             cat << EOF
 Usage:
     ${Q_RUN}[register] [args]
diff --git a/q.sh b/q.sh
index 918871c..5e5e47b 100644
--- a/q.sh
+++ b/q.sh
@@ -54,8 +54,8 @@ preexec_invoke_exec () {
         fi
 
         # Check if trying to set to an existing command
-        if type "q${BASH_REMATCH:1}" > /dev/null 2>&1; then
-            echo "Sorry, \"q${MATCH:1}\" is already a command in your \$PATH! :("
+        if type "${Q_RUN}${BASH_REMATCH:1}" > /dev/null 2>&1; then
+            echo "Sorry, \"${Q_RUN}${MATCH:1}\" is already a command in your \$PATH! :("
             BUFFER=""
             return 1
         fi
@@ -66,7 +66,7 @@ preexec_invoke_exec () {
 
         # If called without register, show help
         if [[ $REG == "" ]]; then
-            echo "q - registers for zsh"
+            echo "${Q_RUN} - registers for zsh"
             cat << EOF
 Usage:
     $Q_RUN[register] [args]
-- 
2.34.1

Everything broken if using this

I really like this script. But if using it in Ubuntu 14.04 bash strange things happens.

For example if executing simple things like

echo "foo" | grep bar

The grep command does not finish but is somewhat in background. This happens on multiple different configuration of 2 other colleges of mine. We just deinstalled it for now ;(

question about the design

Hi, good idea but why would you ever install a trap for something that doesn't need it? I am probably missing a point, could you please enlighten me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.