Avatar

12510198

12510198@lemmy.blahaj.zone
Joined
2 posts • 34 comments
Direct message

I designed this prompt shortly after I switched to Linux, I’ve been using it for a while, it has a few features like putting the exit code if it isn’t 0, changing the hostname color if its detected that you are over ssh, changing the directory color to red if it isn’t writeable, changing the prompt color to red if your euid is 0, and instead of printing I have no name! when your user does not have an entry in the passwd file, it will just print your uid in red. I also have a version that I wrote in C that works the same way with a subsitution shell, but it was harder to sync across all my devices when I made a change, so I rewrote it in posix shell that could be synced with just my .bashrc and work almost anywhere.

I don’t know how to post a screenshot, sorry for the long paragraph, but here is the source code, feel free to share or do whatever with it!

#-----PS1-----#
BOLDRED="\001\033[1;31m\002"
BOLDBLUE="\001\033[1;34m\002"
BOLDPURPLE="\001\033[1;35m\002"
BOLDCYAN="\001\033[1;36m\002"
BOLDGREEN="\001\033[1;32m\002"
COLORRESET="\001\033[0m\002"
CURSOR_BLINK="\001\033[5 q\002"
INFO_COLOR=$BOLDGREEN
SUPERUSER_COLOR=$BOLDRED
NORMALUSER_COLOR=$BOLDCYAN
SSH_COLOR=$BOLDPURPLE
__shellprompt ()
{
        if [ "$(id -u)" = 0 ]; then
                PROMPT_COLOR=$SUPERUSER_COLOR
                PROMPT_EMBLEM='#'
        else
                PROMPT_COLOR=$NORMALUSER_COLOR
                PROMPT_EMBLEM='$'
        fi
        # [user@hostname]
        printf "%b%s%b" "${PROMPT_COLOR}[${INFO_COLOR}" "$(whoami 2>/dev/null || (printf "%b%s" "${BOLDRED}" "UID:$(id -u)"))" "${PROMPT_COLOR}@"
        if [ -n "${SSH_TTY}" ] || [ -n "${SSH_CLIENT}" ]; then
                printf "%b" "$SSH_COLOR"
        else
                printf "%b" "$INFO_COLOR"
        fi
        printf "%s%b" "$(hostname)" "${PROMPT_COLOR}]"
        # :
        printf "%b" "${COLORRESET}:"
        # (/pwd)
        printf "%b" "${PROMPT_COLOR}("
        if [ -w "$PWD" ]; then
                printf "%b" "${INFO_COLOR}"
        else
                printf "%b" "${BOLDRED}"
        fi
        if [ -n "$HOME" ] && [ "$HOME" != "/" ] && { [ "$PWD" = "$HOME" ] || [ "$PWD" != "${PWD#"$HOME/"}" ]; }; then
                printf "%s" "~${PWD#"$HOME"}"
        else
                printf "%s" "${PWD}"
        fi
        printf "%b" "${PROMPT_COLOR})${COLORRESET}"
        # :(EXITCODE)
        if [ "$1" != 0 ]; then
                printf "%b" "${COLORRESET}:"
                printf "%b%s%b" "${PROMPT_COLOR}(${BOLDRED}" "${1}" "${PROMPT_COLOR})${COLORRESET}"
        fi
        # ->$
        # ->#
        printf "%b" "\n${PROMPT_COLOR}->${PROMPT_EMBLEM} ${COLORRESET}${CURSOR_BLINK}"
}
export PS1='$(__shellprompt $?)'
#-----PS1-----#
permalink
report
reply

A person in this thread already recommended having different colors for different conditions like ssh and running as root, I havent seen anyone mention this specifically but you can determine if the current working directory is writable with something like [ -w "$(pwd)" ] and set the color to red or print a symbol if it doesnt return true.

Also I recommend putting all the code and logic for your shell prompt in a shell function, and using a substitution shell to put it into the PS1 variable like this:

__shellprompt ()
{
	if [ "$(id -u)" = 0 ]; then
		local PROMPT_EMBLEM='#'
	else
		local PROMPT_EMBLEM='$'
	fi
	printf "%s" "$(whoami)@$(uname -n):$(pwd)"
	printf "\n%c " "$PROMPT_EMBLEM"
}
PS1='$(__shellprompt)'

Now this is just a really barebones example, there is a whole lot more you can do like passing in the last exit code through the argv of your shellprompt function like this PS1='$(__shellprompt $?)' and like print it out if its non-zero so you wont have to like echo $? to see if the last command failed, but you should be able to still do this. In my testing, running the shell prompt function in the subsitiution shell didnt effect the $? variable.

In my first comment on another thread about shell prompts, I posted my full shellprompt, it is slightly outdated (I just changed hostname to uname -n), if you cant find it feel free to send a message or just ask, and I will send you the code.

permalink
report
reply

Im glad I was able to help!

Something that should be noted when adding colors to your shell prompt function is adding the non printable characters that keep the terminal from buggin out, this caused me a massive headache until I figured it out. When putting it in the PS1 variable directly you will put \[ to begin a color sequence and \] to end one, but printf will print a literal [ and ] so instead you will have to use \001 to start and \002 to end, I also recommend changing \e to \033 or \x1B to make things a bit more portable. For a quick example \[\e[1;31m\] would become \001\033[1;31m\002. Without these characters the terminal will like glitch out when you type a long command and then go back to the front.

If you are like messing around or trying to learn a new programming language, you can try like porting your shell prompt to that language, Ive ported mine to C and set it using the same subsitution shell method, I thought it was a fun lil challenge.

But anyways, I hope you have fun customizing your shell prompt!

permalink
report
parent
reply

I just gave it a try on my system and it worked just like it did before! Ill have to change my scripts to mount to /run/nextroot instead of /mnt, but i am very relieved that it is still possible. I was having trouble with it all morning. Thank you so much for your reply! It is much appreciated!

permalink
report
parent
reply

I’m prolly a bit late to the post, but I got this cheaper one off of amazon for 30 bucks.

I’ve never used an epilator (and never knew they existed) until quite recently, but I was pleased with its performance. I have these really visible giant black hairs on my chin, so I tried the machine on it and it clamped down on the hairs and ripped them out of their sockets, I dont know the proper term for it but there was like a little “ball” at the origin of the hair which kinda tells me that it took the whole thing out. I’m assuming its gonna grow back but its gonna take a longer period of time before it becomes visible, because it has more hair it has to grow, I dont know how long its gonna take because it just arrived and all happened yesterday.

However, there are some things that should be noted, there are 4 different attachments, I’ve only used one, but the way they attach and connect to the motor are all the same, plastic gears. Now I aint dissassembled the machine, but if I had to guess, id assume that the geartrain inside that connects the motor to the one gear where the attachments attach are probobly made of plastic too. Now I dont have a expensive one to compare, but id assume the build quality is probobly only slightly better, womens products are made with cheap, unreliable components because they want you to buy more. Also the epilator attachment was a bit magnetic on the sides, I’ve been told this is bad because magnetic metal can rust, however I dont really know too much about it. Now I’m not gonna be running it 24/7, fighting against the gears, or dunking it in water, so I figure its gonna last a good while, but not for decades.

Now something else that should be noted is that it didnt do much for my thinner hairs, it ripped out some but for the most part ignored them, mabye they arent long enough, but if you can see the hair and like flick it around with your fingernail it oughta be able to clamp onto it.

Also something good is that it doesnt require any stupid “app”, any program, it doesnt require wifi, bluetooth, cellular data, a facebook account, a google account, or any stupid nonsense like that. Its just a machine with a switch with 3 states, off, low, and high.

Also something I forgot to talk about is that the ripping the hairs out of its sockets part hurts, I’m guessing you just kinda get used to it, but you might shed a tear or two. If I had to assume, since they all work on the same principal, the expensive models probobly hurt too.

But basically, it works just fine if you dont have much cash or just dont wanna spend a ton of cash on an expensive model.

permalink
report
reply

I took a quick look at the plugin and it looks like it depends on the diff command line utility. I dont think it comes installed with Microsoft Windows, but if you manually installed it, id open a new terminal and try running the diff utility manually to see if its on the executable path.

But if you want to try installing it, I think it comes with Git bash for windows.

I hope this helps, have fun with Neovim!

permalink
report
reply

Dolphin + mpv for me so I can see the album covers and metadata and see whats available, if I have a specific song in mind, then ill just use the terminal and mpv.

permalink
report
reply

I use SSH with port fowarding to securely access my services running on my server to anywhere I have internet. Its easy to setup, just expose any device running a ssh server like openssh to the internet, probably on a port that isnt 22, and with key only authentication.

Then on whatever device you want to get your services on you can do like

ssh -p 8022 -L 8010:192.168.75.111:80 user@serverspublicip

Where 8022 is the port of the ssh server exposed to the internet (default is 22), 8010 is the port its gonna bind to on the device you are using the client (it will bind to 127.0.0.1 by default), 192.168.75.111:80 is the address/hostname and the port of where your services are on your local network, and user@serverspublicip is your username and the ip address of where your ssh server is.

You can also use ssh to make a SOCKS proxy in your network like this

ssh -g -D 1080 user@serverspublicip

This will make a socks proxy into your network on your device at 127.0.0.1:1080. All of this can also be done on just about any mobile phone running android by using termux.

permalink
report
reply

When your browser connects to a website, it will tell the webserver what type of browser you are using in the HTTP headers. This can be used for serving a special web page for browsers with quirks, or it can be used to block certain browsers.

It may look something like this:

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0

But you can use an extension like this one to spoof your user agent and send out one that corresponds to a chromium browser.

permalink
report
parent
reply

If Firefox can read it from disk without a password, any other program running as your user can read it from disk without a password. But to prevent this you can encrypt your Firefox profile with a password.

permalink
report
reply