Ответ 1
Используйте git-status -- <pathspec>...
Сводка git-status
man page говорит вам, что вы можете фильтровать по путям:
git status [<options>...] [--] [<pathspec>...]
Поэтому все, что вам нужно сделать, это получить список путей, соответствующих регулярным (не каталогическим) файлам в текущем каталоге, и передать их на git-status
.
Есть один вопрос: потому что git status
сообщает обо всем репозитории, если он передал пустой аргумент <pathspec>...
, вам нужно проверить, пуст ли пуст или нет.
Shell script
Вот небольшая оболочка script, которая делает то, что вы хотите.
#!/bin/sh
# git-status-dot
#
# Show the status of non-directory files (if any) in the working directory
#
# To make a Git alias called 'status-dot' out of this script,
# put the latter on your search path, make it executable, and run
#
# git config --global alias.status-dot '! git-status-dot'
# Because GIt aliases are run from the top-level directory of the repo,
# we need to change directory back to $GIT_PREFIX.
[ "$GIT_PREFIX" != "" ] && cd "$GIT_PREFIX"
# List Non-Directory Files in the Current Directory
lsnondirdot=$(ls -ap | grep -v /)
# If "lsnondirdot" is not empty, pass its value to "git status".
if [ -n "$lsnondirdot" ]
then
git status -- $lsnondirdot
else
printf "No non-directory files in the working directory\n"
fi
exit $?
Подробнее о том, почему нужны shenanigans GIT_PREFIX
, см. git псевдонимы в неправильном каталоге.
script доступен в Jubobs/git-aliases в GitHub.
Вывести из него Git псевдоним
Для удобства вы можете создать псевдоним Git, который вызывает script; убедитесь, что script находится на вашем пути.
git config --global alias.statusdot '!sh git-status-dot.sh'
Пример игрушки
Вот пример игрушки, демонстрирующий, как использовать полученный псевдоним и что он делает.
# initialize a repo
$ mkdir testgit
$ cd testgit
$ git init
# create two files
$ mkdir foo
$ touch foo/foo.txt
$ touch bar.txt
# good old git status reports that subdir/test1.txt is untracked...
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
bar.txt
foo/
nothing added to commit but untracked files present (use "git add" to track)
# ... whereas our new alias, git status-dot, only cares
# about regular files in the current directory
$ git status-dot
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
bar.txt
nothing added to commit but untracked files present (use "git add" to track)
# and if we delete README.md ...
$ rm README.md
# ... good old git status still bother us about /subdir ...
$ git status
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
foo/
nothing added to commit but untracked files present (use "git add" to track)
# ... whereas git statusdot doesn't
$ git status-dot
No non-directory files in the working directory
$