Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls source to list current directory, most recent first #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions sources/ls.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# zaw-src-ls
#
# list files in current directory, most recent on top
#
# bindkey '^Xl' zaw-ls
#


function zaw-src-ls() {
# avoid any alias present by calling full path
savealias=`alias ls`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use local to restrict scope. You should use command ls if you concern about alias.

[[ "$savealias" = "" ]] || unalias ls

# list ordered by date, newest first
allfiles="$( ls -lt -F )"

[[ "$savealias" = "" ]] || {
# restore ls alias
eval $savealias
unset savealias
}

: ${(A)candidates::=${(f)allfiles}}
actions=(zaw-src-ls-copy zaw-src-ls-append zaw-src-ls-prepend)
act_descriptions=("copy filename to clipboard"
"append filename" "prepend filename")
}

function strip-ls-long() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to zaw-src-ls-strip or some name you prefer to restrict name scope.

awk '
{ fname=$9;
for(i=10; i<=NF; ++i) {
fname = sprintf("%s\\ %s",fname, $i);
}
print fname;
}

'
}

function zaw-src-ls-copy() {
print -- "$1" | strip-ls-long | xclip -in -selection clipboard
BUFFER="${BUFFER}`print -- $1 | strip-ls-long`"
}

function zaw-src-ls-append() {
line="$1"

BUFFER="$BUFFER `print -- $line | strip-ls-long`"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use $LBUFFER and $RBUFFER

}

function zaw-src-ls-prepend() {
line="$1"

BUFFER="`print -- $line | strip-ls-long` $BUFFER"
}


zaw-register-src -n ls zaw-src-ls