Skip to content

Commit 81a1b5c

Browse files
committed
Merge pull request #45 from supercrabtree/new-repomarkers
New repomarkers
2 parents 37ca3af + 4bd1081 commit 81a1b5c

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

README.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,28 @@
1-
![k](https://raw.githubusercontent.com/supercrabtree/k/master/k-logo.png)
1+
![k](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/k-logo.png)
22

33
> k is the new l, yo
44
5-
## Directory listings for zsh with git features.
6-
k is a zsh script to make directory listings more readable, adding a bit of color and some git information.
5+
## Directory listings for zsh with git features
76

8-
### Git status on entire repos
9-
Red for dirty, green for committed.
7+
**k** is a zsh script / plugin to make directory listings more readable, adding a bit of color and some git status information on files and directories.
108

11-
Turns this:
12-
![repos-ls](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/repos-ls.jpg)
9+
### Git status on entire repos
10+
![status-ls](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/repo-dirs.jpg)
1311

14-
Into this:
15-
![repos-k](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/repos-k.jpg)
1612

1713
### Git status on files within a working tree
18-
Red for dirty, green for committed, orange for untracked, grey for ingored.
19-
20-
Turns this:
21-
![status-ls](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/status-ls.jpg)
22-
23-
Into this:
24-
![status-k](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/status-k.jpg)
14+
![status-ls](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/inside-work-tree.jpg)
2515

2616
### File weight colours
2717
Files sizes are graded from green for small (< 1k), to red for huge (> 1mb).
2818

29-
Turns this:
30-
![status-ls](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/size-ls.jpg)
19+
![status-ls](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/file-size-colors.jpg)
3120

32-
Into this:
33-
![status-k](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/size-k.jpg)
3421

3522
### Rotting dates
36-
3723
Dates fade with age.
38-
![repos-k](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/repos-k.jpg)
24+
25+
![repos-k](https://raw.githubusercontent.com/supercrabtree/k/gh-pages/dates.jpg)
3926

4027

4128
## Usage
@@ -51,8 +38,6 @@ hit k
5138
k
5239
```
5340

54-
profit
55-
5641
## Minimum Requirements
5742
zsh 4.3.11
5843
Git 1.7.2

k-logo.png

-1.02 KB
Binary file not shown.

k.sh

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ k () {
6161
fi
6262
}
6363

64+
# Set if we're in a repo or not
65+
typeset -i INSIDE_WORK_TREE=0
66+
if [[ $(command git rev-parse --is-inside-work-tree 2>/dev/null) == true ]]; then
67+
INSIDE_WORK_TREE=1
68+
fi
69+
6470
# Setup array of directories to print
6571
typeset -a base_dirs
6672

@@ -380,23 +386,33 @@ k () {
380386
# --------------------------------------------------------------------------
381387
if [[ "$o_no_vcs" != "" ]]; then
382388
REPOMARKER=""
383-
else
384-
# Check for git repo
385-
if (( IS_GIT_REPO != 0)); then
389+
elif (( IS_GIT_REPO != 0)); then
390+
# If we're not in a repo, still check each directory if it's a repo, and
391+
# then mark appropriately
392+
if (( INSIDE_WORK_TREE == 0 )); then
386393
if (( IS_DIRECTORY )); then
387394
if command git --git-dir="$GIT_TOPLEVEL/.git" --work-tree="${NAME}" diff --quiet --ignore-submodules HEAD &>/dev/null # if dirty
388-
then REPOMARKER=$'\e[38;5;46m|\e[0m' # Show a green vertical bar for dirty
389-
else REPOMARKER=$'\e[0;31m|\e[0m' # Show a red vertical bar if clean
395+
then REPOMARKER=$'\e[38;5;46m|\e[0m' # Show a green vertical bar for clean
396+
else REPOMARKER=$'\e[0;31m+\e[0m' # Show a red vertical bar if dirty
390397
fi
391-
else
392-
STATUS=$(git --git-dir=$GIT_TOPLEVEL/.git --work-tree=$GIT_TOPLEVEL status --porcelain --ignored --untracked-files=normal ${${${NAME:a}##$GIT_TOPLEVEL}#*/})
393-
STATUS=${STATUS[1,2]}
394-
if [[ $STATUS == ' M' ]]; then REPOMARKER=$'\e[0;31m|\e[0m'; # Modified
395-
elif [[ $STATUS == '??' ]]; then REPOMARKER=$'\e[38;5;214m|\e[0m'; # Untracked
396-
elif [[ $STATUS == '!!' ]]; then REPOMARKER=$'\e[38;5;238m|\e[0m'; # Ignored
397-
elif [[ $STATUS == 'A ' ]]; then REPOMARKER=$'\e[38;5;093m|\e[0m'; # Added
398-
else REPOMARKER=$'\e[38;5;082m|\e[0m'; # Good
398+
fi
399+
else
400+
if (( IS_DIRECTORY )); then
401+
# If the directory is ignored, skip it
402+
if command git check-ignore --quiet ${NAME} 2>/dev/null
403+
then STATUS='!!'
404+
else STATUS=$(git --git-dir=$GIT_TOPLEVEL/.git --work-tree=$GIT_TOPLEVEL status --porcelain --untracked-files=normal ${${${NAME:a}##$GIT_TOPLEVEL}#*/})
399405
fi
406+
else
407+
STATUS=$(git status --porcelain --ignored --untracked-files=normal $NAME)
408+
fi
409+
STATUS=${STATUS[1,2]}
410+
if [[ $STATUS == ' M' ]]; then REPOMARKER=$'\e[0;31m+\e[0m'; # Tracked & Dirty
411+
elif [[ $STATUS == 'M ' ]]; then REPOMARKER=$'\e[38;5;082m+\e[0m'; # Tracked & Dirty & Added
412+
elif [[ $STATUS == '??' ]]; then REPOMARKER=$'\e[38;5;214m+\e[0m'; # Untracked
413+
elif [[ $STATUS == '!!' ]]; then REPOMARKER=$'\e[38;5;238m|\e[0m'; # Ignored
414+
elif [[ $STATUS == 'A ' ]]; then REPOMARKER=$'\e[38;5;082m+\e[0m'; # Added
415+
else REPOMARKER=$'\e[38;5;082m|\e[0m'; # Good
400416
fi
401417
fi
402418
fi

0 commit comments

Comments
 (0)