答案1
经过一番挖掘,我找到了解决方法。我将下面的脚本放在我的.bashrc
文件中,这样这些设置就会自动通过 Git Bash 加载。这段代码基于点文件项目。
LS_COMMON="-hG"
LS_COMMON="$LS_COMMON --color=auto"
LS_COMMON="$LS_COMMON -I NTUSER.DAT\* -I ntuser.dat\*"
test -n "$LS_COMMON" &&
alias ls="command ls $LS_COMMON"
alias ll="ls -l"
alias la="ls -a"
alias lal="ll -a"
答案2
我为 thalesmello 的出色解决方案添加了一些文件夹模式。这些文件夹在 Windows 7 上让我很困扰。现在,git bash 中的主文件夹完全是空的。就是这样!
# refers to http://superuser.com/questions/650322/ignore-ntuser-dat-files-when-ls-on-git-bash
LS_COMMON="-hG"
# --color : On Windows7 this produces permission errors, e.g. for Music folder:
# LS_COMMON="$LS_COMMON --color=auto"
LS_COMMON="$LS_COMMON -I NTUSER.DAT\* -I ntuser.dat\*"
LS_COMMON="$LS_COMMON -I AppData\*"
LS_COMMON="$LS_COMMON -I Music\*"
LS_COMMON="$LS_COMMON -I Pictures\*"
LS_COMMON="$LS_COMMON -I Start\ Menu\*"
LS_COMMON="$LS_COMMON -I Application\ Data\*"
LS_COMMON="$LS_COMMON -I Local\ Settings\*"
LS_COMMON="$LS_COMMON -I Cookies\*"
LS_COMMON="$LS_COMMON -I ntuser.ini"
LS_COMMON="$LS_COMMON -I ntuser.pol"
LS_COMMON="$LS_COMMON -I Thumbs.db"
LS_COMMON="$LS_COMMON -I Favorites\*"
LS_COMMON="$LS_COMMON -I Recent\*"
LS_COMMON="$LS_COMMON -I Searches\*"
LS_COMMON="$LS_COMMON -I Videos\*"
LS_COMMON="$LS_COMMON -I Desktop\*"
alias ls="command ls $LS_COMMON"
alias ll="ls -l"
alias la="ls -al"
答案3
感谢之前的回答,Windows 8.1 版本:
添加您的别名:alias ls=ls_filter.bat $*
。
将以下内容保存ls_filter.bat
为%PATH%
:
@REM Runs ls with a filter to exclude some Windows folders, but only when run from the user's home folder.
@if "%CD%" == "%USERPROFILE%" (
ls --color^
-I "AppData" -I "Contacts" -I "Favorites" -I "Links"^
-I "Music" -I "My Documents" -I "Pictures" -I "Videos" -I "Saved Games" -I "Start Menu" -I "OneDrive"^
-I "NTUSER.*" -I "ntuser.*" -I "thumbs.db" -I "Thumbs.db" -I "desktop.ini"^
-I "Application Data" -I "Cookies" -I "NetHood" -I "PrintHood" -I "Local Settings"^
-I "Recent" -I "Searches" -I "SendTo" -I "Templates" %*
) else (
ls --color -I "NTUSER.*" -I "ntuser.*" -I "thumbs.db" -I "Thumbs.db" -I "desktop.ini" %*
)
这样,过滤器仅在您位于主目录中时才适用。在其他目录中时,音乐和视频等文件夹不会被过滤掉。
答案4
alias ls="ls --hide '[Nn][Tt][Uu][Ss][Ee][Rr]*'"