Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Last active August 28, 2025 01:14
Show Gist options
  • Select an option

  • Save chapmanjacobd/5ecb8be86f83dcfdcd043cf3b68b0b27 to your computer and use it in GitHub Desktop.

Select an option

Save chapmanjacobd/5ecb8be86f83dcfdcd043cf3b68b0b27 to your computer and use it in GitHub Desktop.
Select only specific files by their git status
function untracked -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 2) == "??" {print substr($0, 4)}' | string unescape --style=script
end
function added -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 1) == "A" && substr($0, 2, 1) == " " {print substr($0, 4)}' | string unescape --style=script
end
function deleted -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 1) == " " && substr($0, 2, 1) == "D" {print substr($0, 4)}' | string unescape --style=script
end
function deleted.staged -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 1) == "D" && substr($0, 2, 1) == " " {print substr($0, 4)}' | string unescape --style=script
end
function modified -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 1) == " " && substr($0, 2, 1) == "M" {print substr($0, 4)}' | string unescape --style=script
end
function modified.staged -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 1) == "M" && substr($0, 2, 1) == " " {print substr($0, 4)}' | string unescape --style=script
end
function renamed -w 'git status'
git status --porcelain --short $argv | awk '/^R/ {print $NF}' | string unescape --style=script
end
function unmerged -w 'git status'
git status --porcelain --short $argv | awk '$1 ~ /^(DD|AU|UD|UA|DU|AA|UU)/ {print substr($0, 4)}' | string unescape --style=script
end
function changedtype -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 1) == " " && substr($0, 2, 1) == "T" {print substr($0, 4)}' | string unescape --style=script
end
function changedtype.staged -w 'git status'
git status --porcelain --short $argv | awk 'substr($0, 1, 1) == "T" && substr($0, 2, 1) == " " {print substr($0, 4)}' | string unescape --style=script
end
funcsave untracked added deleted deleted.staged modified modified.staged renamed unmerged changedtype changedtype.staged
@chapmanjacobd
Copy link
Author

This is so that you can run something like

$ open (added)

or

$ code (unmerged)

But maybe you already use Magit, etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment