Skip to content

Commit

Permalink
added support for padded line counts
Browse files Browse the repository at this point in the history
  • Loading branch information
GSI2016 committed Jun 22, 2016
1 parent 3259148 commit 01b77ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions clipmenu
Expand Up @@ -9,8 +9,11 @@ CACHE_DIR="/tmp/clipmenu.$USER"
# 'ls' would allow to easily output all files in a sorted manner, but it's use
# should be avoided in scripts.
# With zsh globbing, files could be listed in order like this: files=( *(.oc) )
files_with_timestamps=$(cd $CACHE_DIR && find * | while read -r file ; do stat -c '%Y %n' "$file" ; done)
files_sorted=$(echo "$files_with_timestamps" | sort -rn | cut -d' ' -f2-)
files_with_timestamps=$(cd $CACHE_DIR && find ./ | while read -r file ; do stat -c '%Y %n' "$file" ; done)
# 'cut' removed the recently inserted %Y and find's "./". (In order to support
# files with leading whitespaces, "find *" couldn't be used here.
files_sorted=$(echo "$files_with_timestamps" | sort -rn | cut -c14-)
chosen_file=$(echo "$files_sorted" | dmenu -l 8 "$@")
[[ $chosen_file ]] || exit 1
Expand Down
4 changes: 3 additions & 1 deletion clipmenud
Expand Up @@ -56,7 +56,9 @@ while sleep "${CLIPMENUD_SLEEP:-0.5}"; do
rm -- "${last_filename[$selection]}"
fi

filename="$CACHE_DIR/$(echo "$data" | wc -l)"
lines=$(echo "$data" | wc -l)
# This ALIGNS the line count at the left of any clipboard entry.
filename="$CACHE_DIR/$(printf %2d $lines)"

# We look for the first line matching regex /./ here because we want the
# first line that can provide reasonable context to the user. That is, if
Expand Down

0 comments on commit 01b77ab

Please sign in to comment.