Your top 10 commands - Desktop Customization & Workflow

Users browsing this thread: 1 Guest(s)
josuah
Long time nixers
I think I got polluted by my own ecosystem and do not have a sane workflow like Yuno but....

I rarely do "ls": I use tab to show the list of files, and disable bash specific completion (so that it shows the files even when it expects only directories).

I rarely do "cd": I run most things from some project directory, and I have "cd ~/zephyrproject/zephyr" in ~/.bashrc for whichever project I work on.

1. "xrun" - (which I bound to a keybinding: a script to open a new https://tools.suckless.org/tabbed/ terminal, with an initial command that spawn at every new tab, or if a tabbed window is focused, spawn the command as a tab *inside* the focused window)

2. "$clientname" - (which is an alias to something like "xrun sudo -s -u $clientname" to run a new session in /home/$clientname where every time I spawn a new tab, it's under that user.

3. "root" - alias to "xrun sudo -s" which I call from dmenu to run a temporary terminal tab as root within some other "tabbed" session (i.e. modify /etc/profile where all these aliases are)

4. "o" - open the file on a new local tab, even if it is over SSH: alias to xopen (my xdg-open script with a giant "case $1 in (https://...) ... ;; esac"... or if running from ssh, send "ssh://$HOST/$filename" to "/tmp/$user@host.sock" which is telling my local host to call xdg-open on that, which recognizes "ssh://" and spawns "xrun ssh $HOST $EDITOR $filename"

5. "xssh" - same as ssh, but setups the socket forwarding like used above. Some ad-hoc unixargs.c combines unix socket and xargs, to spawn the xdg-open on every `\n` lines received from the "o" alias (source below)

6. "west" - the command to compile and run unit tests on Zephyr

7. "make" - various projects which uses it

8. "www" - at least once per day to start the big bad browser

9. "irc" - ssh to $HOST and calls "abduco -a irssi" to check out messages

10. "rm -rf" - muahahahahahahaha (delete ./out-twister/ directory or ./build/ that keep spawning on builds)

Code:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <sys/socket.h>
#include <sys/un.h>

#define LINE_SIZE 1024

int recv_first_line(int fd, char *line_buf, size_t line_sz)
{
    char *buf = line_buf;
    size_t sz = line_sz;

    for (ssize_t n; sz > 0 && (n = recv(fd, buf, sz, MSG_WAITALL)) != 0; sz -= n, buf += n) {
        if (n < 0) {
            return -errno;
        }
    }
    line_buf[line_sz - 1] = '\0';
    line_buf[strcspn(line_buf, "\r\n")] = '\0';
    return 0;
}

int handle_connection(int fd, char **argv, char **placeholder)
{
    char line[LINE_SIZE] = {0};
    int err;

    err = shutdown(fd, SHUT_WR);
    if (err) {
        perror("shutdown");
        return -errno;
    }

    err = recv_first_line(fd, line, sizeof(line));
    if (err) {
        perror("recv_first_line");
        return err;
    }

    *placeholder = line;

    printf("unixargs:");
    for (size_t i = 0; argv[i] != NULL; i++) {
        printf(" %s", argv[i]);
    }
    printf("\n");

    switch (fork()) {
    case -1:
        perror("fork");
        return -errno;
    case 0:
        execvp(argv[0], argv);
        perror(argv[0]);
        return -errno;
    }

    return 0;
}

int xserver(char *path, char **argv, char **placeholder)
{
    struct sockaddr_un sun = { .sun_family = AF_UNIX };
    int sockfd, netfd, err;

    sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
    if (sockfd < 0) {
        perror("socket(AF_UNIX)");
        return -errno;
    }

    strncpy(sun.sun_path, path, sizeof(sun.sun_path) - 1);
    err = bind(sockfd, (struct sockaddr *)&sun, sizeof(sun));
    if (err) {
        perror(path);
        return -errno;
    }

    err = listen(sockfd, 10);
    if (err) {
        perror(path);
        return -errno;
    }

    while (true) {
        netfd = accept(sockfd, NULL, NULL);
        if (netfd < 0) {
            perror(path);
            continue;
        }

        handle_connection(netfd, argv, placeholder);
    }

    return 0;
}

void usage(char *argv0)
{
    fprintf(stderr, "Usage: %s ./path.sock cmd [args...] {} [args...]\n", argv0);
    exit(1);
}

int main(int argc, char **argv)
{
    char **placeholder = NULL;
    int err;

    if (argc < 4) {
        usage(argv[0]);
    }

    for (int i = 3; i < argc; i++) {
        if (strcmp(argv[i], "{}") == 0) {
            placeholder = &argv[i];
            break;
        }
    }
    if (placeholder == NULL) {
        usage(argv[0]);
    }

    err = xserver(argv[1], argv + 2, placeholder);
    if (err) {
        fprintf(stderr, "failed to run xserver, exiting\n");
        return -err;
    }

    return 0;
}

P.S.: I know I can use tmux to skip all of that messy business, but I'm trapped in my own habits, please come save me! (;_;) :P


Messages In This Thread
Your top 10 commands - by seninha - 14-10-2021, 11:10 PM
RE: Your top 10 commands - by z3bra - 15-10-2021, 02:26 AM
RE: Your top 10 commands - by tuxifreund - 15-10-2021, 02:52 AM
RE: Your top 10 commands - by ols - 15-10-2021, 06:36 AM
RE: Your top 10 commands - by dionys - 15-10-2021, 08:13 AM
RE: Your top 10 commands - by seninha - 15-10-2021, 08:39 AM
RE: Your top 10 commands - by freem - 15-10-2021, 01:07 PM
RE: Your top 10 commands - by humky - 19-10-2021, 07:59 PM
RE: Your top 10 commands - by venam - 20-10-2021, 05:48 AM
RE: Your top 10 commands - by z3bra - 20-10-2021, 02:39 PM
RE: Your top 10 commands - by freem - 22-10-2021, 11:52 AM
RE: Your top 10 commands - by humky - 22-10-2021, 03:42 PM
RE: Your top 10 commands - by z3bra - 25-10-2021, 05:47 AM
RE: Your top 10 commands - by humky - 25-10-2021, 10:48 AM
RE: Your top 10 commands - by VMS - 28-02-2022, 11:48 AM
RE: Your top 10 commands - by venam - 01-03-2022, 06:04 AM
RE: Your top 10 commands - by VMS - 01-03-2022, 02:50 PM
RE: Your top 10 commands - by jkl - 05-03-2022, 10:27 AM
RE: Your top 10 commands - by Hatbox - 05-03-2022, 01:08 PM
RE: Your top 10 commands - by yuno - 23-10-2024, 09:31 PM
RE: Your top 10 commands - by josuah - 24-10-2024, 06:27 AM
RE: Your top 10 commands - by josuah - 24-10-2024, 06:34 AM
RE: Your top 10 commands - by maksim - 08-11-2024, 09:30 AM