aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile25
-rw-r--r--dmenu.112
-rwxr-xr-xdmenu_path9
-rwxr-xr-xdmenu_run9
-rw-r--r--lsx.111
-rw-r--r--lsx.c38
6 files changed, 77 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index 5871fa7..f3f6b3d 100644
--- a/Makefile
+++ b/Makefile
@@ -3,10 +3,10 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = dmenu.c draw.c 6SRC = dmenu.c draw.c lsx.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options dmenu 9all: options dmenu lsx
10 10
11options: 11options:
12 @echo dmenu build options: 12 @echo dmenu build options:
@@ -20,9 +20,13 @@ options:
20 20
21${OBJ}: config.mk 21${OBJ}: config.mk
22 22
23dmenu: ${OBJ} 23dmenu: dmenu.o draw.o
24 @echo CC -o $@ 24 @echo CC -o $@
25 @${CC} -o $@ ${OBJ} ${LDFLAGS} 25 @${CC} -o $@ dmenu.o draw.o ${LDFLAGS}
26
27lsx: lsx.o
28 @echo CC -o $@
29 @${CC} -o $@ lsx.o ${LDFLAGS}
26 30
27clean: 31clean:
28 @echo cleaning 32 @echo cleaning
@@ -31,7 +35,7 @@ clean:
31dist: clean 35dist: clean
32 @echo creating dist tarball 36 @echo creating dist tarball
33 @mkdir -p dmenu-${VERSION} 37 @mkdir -p dmenu-${VERSION}
34 @cp LICENSE Makefile README config.mk dmenu.1 draw.h dmenu_path dmenu_run ${SRC} dmenu-${VERSION} 38 @cp LICENSE Makefile README config.mk dmenu.1 draw.h dmenu_run ${SRC} dmenu-${VERSION}
35 @tar -cf dmenu-${VERSION}.tar dmenu-${VERSION} 39 @tar -cf dmenu-${VERSION}.tar dmenu-${VERSION}
36 @gzip dmenu-${VERSION}.tar 40 @gzip dmenu-${VERSION}.tar
37 @rm -rf dmenu-${VERSION} 41 @rm -rf dmenu-${VERSION}
@@ -39,21 +43,24 @@ dist: clean
39install: all 43install: all
40 @echo installing executables to ${DESTDIR}${PREFIX}/bin 44 @echo installing executables to ${DESTDIR}${PREFIX}/bin
41 @mkdir -p ${DESTDIR}${PREFIX}/bin 45 @mkdir -p ${DESTDIR}${PREFIX}/bin
42 @cp -f dmenu dmenu_path dmenu_run ${DESTDIR}${PREFIX}/bin 46 @cp -f dmenu dmenu_run lsx ${DESTDIR}${PREFIX}/bin
43 @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu 47 @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu
44 @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_path
45 @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_run 48 @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_run
46 @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 49 @chmod 755 ${DESTDIR}${PREFIX}/bin/lsx
50 @echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
47 @mkdir -p ${DESTDIR}${MANPREFIX}/man1 51 @mkdir -p ${DESTDIR}${MANPREFIX}/man1
48 @sed "s/VERSION/${VERSION}/g" < dmenu.1 > ${DESTDIR}${MANPREFIX}/man1/dmenu.1 52 @sed "s/VERSION/${VERSION}/g" < dmenu.1 > ${DESTDIR}${MANPREFIX}/man1/dmenu.1
53 @sed "s/VERSION/${VERSION}/g" < lsx.1 > ${DESTDIR}${MANPREFIX}/man1/lsx.1
49 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/dmenu.1 54 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/dmenu.1
55 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/lsx.1
50 56
51uninstall: 57uninstall:
52 @echo removing executables from ${DESTDIR}${PREFIX}/bin 58 @echo removing executables from ${DESTDIR}${PREFIX}/bin
53 @rm -f ${DESTDIR}${PREFIX}/bin/dmenu 59 @rm -f ${DESTDIR}${PREFIX}/bin/dmenu
54 @rm -f ${DESTDIR}${PREFIX}/bin/dmenu_path
55 @rm -f ${DESTDIR}${PREFIX}/bin/dmenu_run 60 @rm -f ${DESTDIR}${PREFIX}/bin/dmenu_run
61 @rm -f ${DESTDIR}${PREFIX}/bin/lsx
56 @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 62 @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
57 @rm -f ${DESTDIR}${MANPREFIX}/man1/dmenu.1 63 @rm -f ${DESTDIR}${MANPREFIX}/man1/dmenu.1
64 @rm -f ${DESTDIR}${MANPREFIX}/man1/lsx.1
58 65
59.PHONY: all options clean dist install uninstall 66.PHONY: all options clean dist install uninstall
diff --git a/dmenu.1 b/dmenu.1
index 8295d17..616a2a5 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -23,12 +23,10 @@ dmenu \- dynamic menu
23.RB [ \-v ] 23.RB [ \-v ]
24.P 24.P
25.BR dmenu_run " ..." 25.BR dmenu_run " ..."
26.P
27.B dmenu_path
28.SH DESCRIPTION 26.SH DESCRIPTION
29.B dmenu 27.B dmenu
30is a dynamic menu for X, originally designed for 28is a dynamic menu for X, originally designed for
31.BR dwm (1). 29.IR dwm (1).
32It manages huge numbers of user\-defined menu items efficiently. 30It manages huge numbers of user\-defined menu items efficiently.
33.P 31.P
34dmenu reads a list of newline\-separated items from stdin and creates a menu. 32dmenu reads a list of newline\-separated items from stdin and creates a menu.
@@ -36,11 +34,8 @@ When the user selects an item or enters any text and presses Return, their
36choice is printed to stdout and dmenu terminates. 34choice is printed to stdout and dmenu terminates.
37.P 35.P
38.B dmenu_run 36.B dmenu_run
39is a dmenu script used by dwm which lists programs in the user's PATH and 37is a dmenu script used by dwm which lists programs in the user's $PATH and
40executes the selected item. 38executes the selected item.
41.P
42.B dmenu_path
43is a script used by dmenu_run to find and cache a list of executables.
44.SH OPTIONS 39.SH OPTIONS
45.TP 40.TP
46.B \-b 41.B \-b
@@ -100,4 +95,5 @@ Exit without selecting an item, returning failure.
100.B Ctrl\-y 95.B Ctrl\-y
101Paste the current X selection into the input field. 96Paste the current X selection into the input field.
102.SH SEE ALSO 97.SH SEE ALSO
103.BR dwm (1) 98.IR dwm (1),
99.IR lsx (1)
diff --git a/dmenu_path b/dmenu_path
deleted file mode 100755
index 1b1b241..0000000
--- a/dmenu_path
+++ /dev/null
@@ -1,9 +0,0 @@
1#!/bin/sh
2CACHE=$HOME/.dmenu_cache
3IFS=:
4
5if ! test -f "$CACHE" || find $PATH -type d -newer "$CACHE" | grep -q .; then
6 find $PATH ! -type d \( -perm -1 -o -perm -10 -o -perm -100 \) | sed 's/.*\///' | sort -u > "$CACHE"
7fi
8
9cat "$CACHE"
diff --git a/dmenu_run b/dmenu_run
index 3e1e6e4..6e96b38 100755
--- a/dmenu_run
+++ b/dmenu_run
@@ -1,2 +1,9 @@
1#!/bin/sh 1#!/bin/sh
2exe=`dmenu_path | dmenu ${1+"$@"}` && exec $exe 2CACHE=${XDG_CACHE_HOME:-"$HOME/.cache"}/dmenu_run
3(
4 IFS=:
5 if test "`ls -dt $PATH "$CACHE" 2> /dev/null | sed 1q`" != "$CACHE"; then
6 mkdir -p "`dirname "$CACHE"`" && lsx $PATH | sort -u > "$CACHE"
7 fi
8)
9cmd=`dmenu "$@" < "$CACHE"` && exec $cmd
diff --git a/lsx.1 b/lsx.1
new file mode 100644
index 0000000..1b2a15e
--- /dev/null
+++ b/lsx.1
@@ -0,0 +1,11 @@
1.TH LSX 1 dmenu\-VERSION
2.SH NAME
3lsx \- list executables
4.SH SYNOPSIS
5.B lsx
6.RI [ directory ...]
7.SH DESCRIPTION
8.B lsx
9lists the executables in each
10.IR directory .
11If none are given the current working directory is used.
diff --git a/lsx.c b/lsx.c
new file mode 100644
index 0000000..e5b5c0b
--- /dev/null
+++ b/lsx.c
@@ -0,0 +1,38 @@
1/* See LICENSE file for copyright and license details. */
2#include <dirent.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <unistd.h>
7#include <sys/stat.h>
8
9static void lsx(const char *dir);
10
11int
12main(int argc, char *argv[]) {
13 int i;
14
15 if(argc < 2)
16 lsx(".");
17 else for(i = 1; i < argc; i++)
18 lsx(argv[i]);
19 return EXIT_SUCCESS;
20}
21
22void
23lsx(const char *dir) {
24 char buf[PATH_MAX];
25 struct dirent *d;
26 struct stat st;
27 DIR *dp;
28
29 if(!(dp = opendir(dir))) {
30 perror(dir);
31 return;
32 }
33 while((d = readdir(dp)))
34 if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < sizeof buf
35 && !stat(buf, &st) && S_ISREG(st.st_mode) && access(buf, X_OK) == 0)
36 puts(d->d_name);
37 closedir(dp);
38}