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

Kakoune compat #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dist: clean
@cp -R LICENSE Makefile README.md testsuite.sh config.def.h config.mk \
${SRC} vt.h forkpty-aix.c forkpty-sunos.c tile.c bstack.c \
tstack.c vstack.c grid.c fullscreen.c fibonacci.c \
dvtm-status dvtm.info dvtm.1 dvtm-${VERSION}
dvtm-status dvtm-cmd dvtm.info dvtm-cmd.1 dvtm.1 dvtm-${VERSION}
@tar -cf dvtm-${VERSION}.tar dvtm-${VERSION}
@gzip dvtm-${VERSION}.tar
@rm -rf dvtm-${VERSION}
Expand All @@ -51,18 +51,24 @@ install: dvtm
@chmod 755 ${DESTDIR}${PREFIX}/bin/dvtm
@cp -f dvtm-status ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/dvtm-status
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
@cp -f dvtm-cmd ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/dvtm-cmd
@echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
@sed "s/VERSION/${VERSION}/g" < dvtm.1 > ${DESTDIR}${MANPREFIX}/man1/dvtm.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dvtm.1
@cp -f dvtm-cmd.1 ${DESTDIR}${MANPREFIX}/man1/dvtm-cmd.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dvtm-cmd.1
@echo installing terminfo description
@TERMINFO=${TERMINFO} tic -s dvtm.info

uninstall:
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
@rm -f ${DESTDIR}${PREFIX}/bin/dvtm
@rm -f ${DESTDIR}${PREFIX}/bin/dvtm-status
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
@rm -f ${DESTDIR}${PREFIX}/bin/dvtm-cmd
@echo removing manual pages from ${DESTDIR}${MANPREFIX}/man1
@rm -f ${DESTDIR}${MANPREFIX}/man1/dvtm.1
@rm -f ${DESTDIR}${MANPREFIX}/man1/dvtm-cmd.1

.PHONY: all options clean dist install uninstall debug
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ static Cmd commands[] = {
{ "focus", { focusid, { NULL } } },
/* tag <win_id> <tag> [tag ...]: replace the tags of the window with the given identifier */
{ "tag", { tagid, { NULL } } },
/* untag <win_id> <tag> [tag ...]: remove the tags of the window with the given identifier */
{ "untag", { untagid, { NULL } } },
};

/* gets executed when dvtm is started */
Expand Down
74 changes: 74 additions & 0 deletions dvtm-cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh

DVTM_CMD_FIFO='/tmp/dvtm.fifo'

# Print a message on the standard error and quit the script
fatal() {
printf %s\\n "$@" 1>&2
exit 1
}

# Print a usage string and exit the script
usage() {
printf %s\\n "Usage: $0 [-h] [ -c <cmd_fifo> ] command [ args ... ]"
echo
echo "The following commands are supported, refer to the dvtm-cmd(1) manpage for more information:"
printf ' - %s %s\n' "create [cmd] " "Create a new client and optionally run a command in it"
printf ' - %s %s\n' "focus <win_id> " "Focus the given window"
printf ' - %s %s\n' "tag <win_id> <tag> ... " "Assign tags to the given window"
printf ' - %s %s\n' "untag <win_id> <tag> ..." "Remove tags from the given window"
exit
}

# Send a command to the command FIFO
send_command() {
printf %s\\n "$*" > "${DVTM_CMD_FIFO}"
}

main() {
## Get CLI option values
while getopts hc: o; do
case $o in
c) DVTM_CMD_FIFO="${OPTARG}";;
?) usage;;
esac
done
shift $((OPTIND - 1))

## Check the arguments passed
if [ $# -lt 1 ]; then
fatal "No command passed"
elif [ ! -p "${DVTM_CMD_FIFO}" ]; then
fatal "No such named pipe: ${DVTM_CMD_FIFO}"
fi

## Execute the command
command="$1"; shift
case "${command}" in
create)
if [ $# -ge 1 ]; then
send_command "create" "'$*'"
else
send_command "create"
fi
;;
focus)
if [ $# -eq 1 ]; then
send_command "${command}" "$1"
else
fatal "Not enough arguments (expected 1)"
fi
;;
untag|tag)
if [ $# -ge 2 ]; then
win_id="$1"; shift
send_command "${command}" "${win_id}" "$@"
else
fatal "Not enough arguments (expected at least 2)"
fi
;;
*) fatal "Invalid command: ${command}";;
esac
}

main "$@"
86 changes: 86 additions & 0 deletions dvtm-cmd.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'\" t
.\" Title: dvtm-cmd
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" Date: 10/04/2016
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "DVTM\-CMD" "1" "10/04/2016" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
dvtm-cmd \- an external wrapper script to interact with dvtm
.SH "SYNOPSIS"
.sp
dvtm\-cmd [\-h] [\-c cmd_fifo] command [args \&...]
.SH "DESCRIPTION"
.sp
The \fBdvtm\-cmd\fR utility is a shell script that allows interacting with and controlling the \fBdvtm\fR terminal multiplexer\&. The commands are formatted in a format understand by \fBdvtm\fR and sent over the \fBcmd_fifo\fR file\&.
.SH "ENVIRONMENT"
.sp
New windows created by \fBdvtm\fR automatically spawn a shell (unless a command has been passed, c\&.f\&. the \fBCOMMANDS\fR section of this document), which will contain the following variables:
.PP
\fBDVTM\fR (version)
.RS 4
version of the currently running
\fBdvtm\fR
session
.RE
.PP
\fBDVTM_WINDOW_ID\fR (integer)
.RS 4
identifier of the current window
.RE
.PP
\fBDVTM_CMD_FIFO\fR (file path)
.RS 4
path to the command FIFO that was passed to the currently running
\fBdvtm\fR
session\&. If no such path was passed when
\fBdvtm\fR
was started, this variable is undefined
.RE
.SH "COMMANDS"
.sp
Due to technical limitations, the maximum amount of arguments a command can take is limited to \fI4\fR\&.
.PP
\fBcreate\fR [command]
.RS 4
create a new window in the current session, and pass
\fIcommand\fR
to the shell\(cqs
\fI\-c\fR
flag if specified
.RE
.PP
\fBfocus\fR <window_id>
.RS 4
focus the window whose identifier is
\fIwindow_id\fR
.RE
.PP
\fBtag\fR <window_id> <tag> \&...
.RS 4
assign the given tags to the window whose identifier is
\fIwindow_id\fR
(the tags previously assigned will be overwritten)
.RE
18 changes: 18 additions & 0 deletions dvtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static void setmfact(const char *args[]);
static void startup(const char *args[]);
static void tag(const char *args[]);
static void tagid(const char *args[]);
static void untagid(const char *args[]);
static void togglebar(const char *args[]);
static void togglebarpos(const char *args[]);
static void toggleminimize(const char *args[]);
Expand Down Expand Up @@ -816,6 +817,23 @@ tagid(const char *args[]) {
}
}

static void
untagid(const char *args[]) {
if (!args[0] || !args[1])
return;

const int win_id = atoi(args[0]);
for (Client *c = clients; c; c = c->next) {
if (c->id == win_id) {
unsigned int i;
for (i = 1; i < MAX_ARGS && args[i]; i++)
c->tags &= ~(bitoftag(args[i]) & TAGMASK);
tagschanged();
return;
}
}
}

static void
toggletag(const char *args[]) {
if (!sel)
Expand Down