You are not logged in.

#1 2010-04-22 18:14:18

Jiran
Member
Registered: 2009-01-29
Posts: 17

Using "less" with directories

So I tried installing Gentoo not too long ago (to no avail, though, X didn't work), and while using it I noticed that if I typed "less some_directory", then it would output either the contents of the directory or the contents of the pwd, I forget which one. However, in Arch, typing "less some_directory" will output "some_directory is a directory", so I have to use "ls some_directory". Does anyone know how to change less to be able to work with directories as well?

Thanks in advance!

Offline

#2 2010-04-22 18:24:52

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Using "less" with directories

This is what I get when I 'vim menu_test'

" ============================================================================
" Netrw Directory Listing                                        (netrw v132)
"   /home/karol/menu_test
"   Sorted by      name
"   Sort sequence: [\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
"   Quick Help: <F1>:help  -:go up dir  D:delete  R:rename  s:sort-by  x:exec
" ============================================================================
../
pacpackgs.lst
t1*
.swp
pacpackgs.lst~

How to do it w/ less - idk.

Offline

#3 2010-04-22 19:36:08

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: Using "less" with directories

Probably means they have a specialized version of less .... -or- there might be a a less option that does it and which is invoked by default (man less), (env.variable LESSOPEN?)

Offline

#4 2010-04-22 19:40:02

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: Using "less" with directories

Install "lesspipe" from [community]. It comes with a profile.d entry that sets LESSOPEN for you so it's just plug-and-play.

Offline

#5 2010-04-22 20:09:50

destruct
Member
Registered: 2009-12-24
Posts: 14

Re: Using "less" with directories

Another Solution.

ls | less

Offline

#6 2010-04-22 20:32:39

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: Using "less" with directories

... or *chuckles*

 alias clueless="ls -al $* | less"

Offline

#7 2010-04-22 20:51:32

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Using "less" with directories

A more hands-on approach would be to start a command when less fails. Like less "$file" 2>/dev/null || ..... or see if it is a directory beforehand.
I thought it would be fun to write a small recursive file chooser:

function less() {
/bin/less "$1" 2>/dev/null || { IFS=$'\n';i=1;k=1;files=$(ls -1 "$1"); [ -z "$files" ] && { echo "Empty directory"; return; }; while [ $k != q -a $k != enter ]; do c=0; for file in $files; do ((i==++c)) && echo -e '\e[30;47m'"$file"'\e[m' || echo "$file"; done; read -n1 -s k; ! [ $k ] && { k=enter; echo; break; }; [ $k = A ] && ((i--)); [ $k = B ] && ((i++)); [ $k = q ] && break; echo -ne "\e[${c}A"; done; read -t 0.1; [ $k = enter ] && less "$1/$(echo "$files" | sed -n "$i"'{p;q}')"; }
}

Offline

Board footer

Powered by FluxBB