commit
49672e9d05
6 changed files with 77 additions and 27 deletions
@ -1,9 +0,0 @@ |
||||
#!/bin/sh |
||||
CACHE=$HOME/.dmenu_cache |
||||
IFS=: |
||||
|
||||
if ! test -f "$CACHE" || find $PATH -type d -newer "$CACHE" | grep -q .; then |
||||
find $PATH ! -type d \( -perm -1 -o -perm -10 -o -perm -100 \) | sed 's/.*\///' | sort -u > "$CACHE" |
||||
fi |
||||
|
||||
cat "$CACHE" |
@ -1,2 +1,9 @@ |
||||
#!/bin/sh |
||||
exe=`dmenu_path | dmenu ${1+"$@"}` && exec $exe |
||||
CACHE=${XDG_CACHE_HOME:-"$HOME/.cache"}/dmenu_run |
||||
( |
||||
IFS=: |
||||
if test "`ls -dt $PATH "$CACHE" 2> /dev/null | sed 1q`" != "$CACHE"; then |
||||
mkdir -p "`dirname "$CACHE"`" && lsx $PATH | sort -u > "$CACHE" |
||||
fi |
||||
) |
||||
cmd=`dmenu "$@" < "$CACHE"` && exec $cmd |
||||
|
@ -0,0 +1,11 @@ |
||||
.TH LSX 1 dmenu\-VERSION |
||||
.SH NAME |
||||
lsx \- list executables |
||||
.SH SYNOPSIS |
||||
.B lsx |
||||
.RI [ directory ...] |
||||
.SH DESCRIPTION |
||||
.B lsx |
||||
lists the executables in each |
||||
.IR directory . |
||||
If none are given the current working directory is used. |
@ -0,0 +1,38 @@ |
||||
/* See LICENSE file for copyright and license details. */ |
||||
#include <dirent.h> |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <unistd.h> |
||||
#include <sys/stat.h> |
||||
|
||||
static void lsx(const char *dir); |
||||
|
||||
int |
||||
main(int argc, char *argv[]) { |
||||
int i; |
||||
|
||||
if(argc < 2) |
||||
lsx("."); |
||||
else for(i = 1; i < argc; i++) |
||||
lsx(argv[i]); |
||||
return EXIT_SUCCESS; |
||||
} |
||||
|
||||
void |
||||
lsx(const char *dir) { |
||||
char buf[PATH_MAX]; |
||||
struct dirent *d; |
||||
struct stat st; |
||||
DIR *dp; |
||||
|
||||
if(!(dp = opendir(dir))) { |
||||
perror(dir); |
||||
return; |
||||
} |
||||
while((d = readdir(dp))) |
||||
if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < sizeof buf |
||||
&& !stat(buf, &st) && S_ISREG(st.st_mode) && access(buf, X_OK) == 0) |
||||
puts(d->d_name); |
||||
closedir(dp); |
||||
} |
Loading…
Reference in new issue