Skip to main content
Added example
Source Link
Tarmo
  • 109
  • 4

I'd like to create some functions/aliases in my .zshrc to help with git, but I'm not sure how.

First one:

Full command: git commit -s -m "My message"

My desired end result: gsc -m "My message"

Second one:

Full command: git commit -s -a -m "My message"

My desired end result: gsca "My message"

As you can see I want a macro that would call something with partial arguments and accept all other arguments whatever they may be from this macros call.

What I tried:

  1. function gsc() { git commit -s $@; }
  2. alias gsc='git commit -s'

Neither of those worked.

My test:

> gsc -a -m "test"
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    smth.txt

nothing added to commit but untracked files present (use "git add" to track

I'd like to create some functions/aliases in my .zshrc to help with git, but I'm not sure how.

First one:

Full command: git commit -s -m "My message"

My desired end result: gsc -m "My message"

Second one:

Full command: git commit -s -a -m "My message"

My desired end result: gsca "My message"

As you can see I want a macro that would call something with partial arguments and accept all other arguments whatever they may be from this macros call.

What I tried:

  1. function gsc() { git commit -s $@; }
  2. alias gsc='git commit -s'

Neither of those worked.

I'd like to create some functions/aliases in my .zshrc to help with git, but I'm not sure how.

First one:

Full command: git commit -s -m "My message"

My desired end result: gsc -m "My message"

Second one:

Full command: git commit -s -a -m "My message"

My desired end result: gsca "My message"

As you can see I want a macro that would call something with partial arguments and accept all other arguments whatever they may be from this macros call.

What I tried:

  1. function gsc() { git commit -s $@; }
  2. alias gsc='git commit -s'

Neither of those worked.

My test:

> gsc -a -m "test"
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    smth.txt

nothing added to commit but untracked files present (use "git add" to track
Source Link
Tarmo
  • 109
  • 4

How to create zsh/bash macro with partial arguments

I'd like to create some functions/aliases in my .zshrc to help with git, but I'm not sure how.

First one:

Full command: git commit -s -m "My message"

My desired end result: gsc -m "My message"

Second one:

Full command: git commit -s -a -m "My message"

My desired end result: gsca "My message"

As you can see I want a macro that would call something with partial arguments and accept all other arguments whatever they may be from this macros call.

What I tried:

  1. function gsc() { git commit -s $@; }
  2. alias gsc='git commit -s'

Neither of those worked.