Xmonad keybindings for thunderbird and dmenu - xmonad

I've been trying to get these two keybindings to work on my Xmonad setup for a while now, but alas I have failed. I want thunderbird to spawn on a certain workspace and demenu to run on the workspace that is currently being viewed. Here is the relavent part of my current keybinding setup:
keys' conf#(XConfig {XMonad.modmask = modmask}) = M.fromList $
[ ((modMask, xK_d), spawnOn "2:Web" "dwb")
, ((modMask, xK-r), spawn "dmenu_run")
, ((modMask, xK_e), spawnOn "3:Email" "Mail"
...other keybindings that work.....
]
The dwb keybinding does work. In the thunderbird one, in place of "Mail" I have also tried "thunderbird" and "Thunderbird" to no avail.
I would certainly appreciate it if anyone can make this work for me. It gets annoying opening up thunderbird from a terminal.

Whatever you type from the terminal to open Thunderbird should work as the third parameter of spawnOn. If all else fails, try the full path to the thunderbird executable.
For others who might google this, if don't know what to type in a terminal to launch a program, launch however you normally launch it (e.g. from a menu or using a key binding), and then type ps -ef to find the name of the command.

Try to replace "Mail" with "thunderbird"
, ((modMask, xK_e), spawnOn "3:Email" "Mail"
To
, ((modMask, xK_e), spawnOn "3:Email" "thunderbird"
If it still doesn't work, check if some other key configuration overwrite the key "e".

The default config maps (modMask, xK_e) to "Switch to physical/Xinerama screen 2". Be sure you disabled/changed it.

Use the cli tool xprop and click on Thunderbird, it shows you the Class name of Thunderbird, which you need to place here:
, ((modMask, xK_e), spawnOn "3:Email" "ClassName"

Related

Ranger filemanager defaulting to nano

I set Ranger as a keybind with Awesome Window Manager (AWM). My environmental variables and shell (ZSH) for both visual and editor are set to VIM. When I use the keybind (super + f), Ranger defaults the editor to Nano.
The man page for Ranger says that it defaults to VIM.
I have no idea why it is doing this.
'''
awful.key({ modkey }, "f", function () awful.util.spawn( "alacritty -e 'ranger'" ) end,
359 {description = "ranger" , group = "super"}),
'''
^^^This is the keybind.
Something probably set the EDITOR environment, somewhere. Follow these steps to fix it:
Open /etc/passwd and make sure your shell is zsh
Make sure you have export EDITOR=/usr/bin/vim in ~/.zshrc
Replace awful.util.spawn with awful.spawn.with_shell. This ensure it reads ~/.zshrc instead of launching range with an "empty" environment.

Start applications on specific workspace if not yet started there

In short: when I switch to workspace X, I want some programs to autostart, but only if they're not already started.
This is different from XMonad startup on different workspaces as I don't want to move windows to specific workspaces (like always moving xterm to workspace 2).
This doesn't work for me, either: xmonad spawn on startup in different workspace. I don't want all applications to start immediately as I log in, also this won't autostart e.g. xterm if I close it and switch to workspace 2 again.
Enough about what doesn't work, here is what does work:
(almost)
In my workspace list I hold touples with the workspace name and a list programs to start when I switch there:
myWorkspaces = [ ("VIM", ["gvim"]), ("TERM",[myTerminal ++ " -e tmux"]) ]
-- In my keybindings:
[ ((mod4Mask, key), loadWorkspace workspace cmd)
| (key, (workspace, cmd)) <- zip [xK_1..] myWorkspaces
]
I defined a function to switch to a workspace and spawn the given programs:
loadWorkspace :: String -> [String] -> X()
loadWorkspace workspace commands =
do windows $ W.greedyView workspace
mapM_ spawn filtered_commands
where filtered_commands :: X [String]
filtered_commands = filterM isNotOpen commands
isNotOpen :: String -> X Bool
isNotOpen command = return True
(For some reason mapM_ requires the second argument to be a String instead of [String]. I want to map spawn over the strings in filtered_commands, any idea why this doesn't work?)
The last missing piece is the isNotOpen function, which should search the classNames of the windows in the current workspace and return whether command is already there.
I find it extremely hard (compared to other languages and technologies) to search for the XMonad way to do things. For this case I could only find how to get the windows in the current WS - https://superuser.com/a/852152/481701. Ok, I think, this gives me a Window object, I can query it for some attributes.
But no. The Window is actually... alias for Word64!!! Ok, I think. Google xmonad get window attributes. Nothing. xmonad get classname from window id. Nothing. xmonad window information. And a dozen other ways to say something similar - no helpful results. All I get is the xmonad homepage, the FAQ, or "Xmonad configuration tips".
I tried these in hayoo!, too, and the closest I could get was "fromClassName - Colorize a window depending on it's className.". Haha.
So, how can I get a window's className (or any other attributes) outside of ManageHook?
You might like dynamic projects or topic spaces as prebaked alternatives. They don't do exactly what you propose, but perhaps one of them is close enough to still be useful, and require less configuration work.
I want to map spawn over the strings in filtered_commands, any idea why this doesn't work?
Yep, you need to lift mapM_ to handle a monadic argument (as opposed to a monadic function or return value). Thus:
filtered_commands >>= mapM_ spawn
Or, since you are already in a do block:
result_of_filtered_commands <- filtered_commands
mapM_ spawn result_of_filtered_commands
So, how can I get a window's className (or any other attributes) outside of ManageHook?
Look at the source of className:
className = ask >>= (\w -> liftX $ withDisplay $ \d -> fmap resClass $ io $ getClassHint d w)
You can take just the argument to liftX as an X action rather than a Query action. The key function is getClassHint from the X11 package. That package also offers access to other attributes of windows.
Install wmctrl
sudo apt install wmctrl
And create a script (in this example thunderbird on the second workspace (-t 1)):
#!/bin/sh
(thunderbird &) & sleep 5 &&
sh -c "wmctrl -i -r `wmctrl -l | grep Thunderbird` -t 1"
To know your application name on wmctrl you can view it by taping on your terminal :
wmctrl -l
And replace it with the correct name in the script.
Be carrefull with the capital letter ("Thunderbird" not "thunderbird") !!
Other example with firefox on the 3d workspace (-t 2):
#!/bin/sh
(firefox &) & sleep 5 &&
sh -c "wmctrl -i -r `wmctrl -l | grep Firefox` -t 2"
Bonus :
Here is the command to execute at start-up :
sh -c "thunderbird & sleep 5 && wmctrl -i -r `wmctrl -l | grep Thunderbird` -t 1"
Work on Debain 10 with Cinnamon. But should work for all

Turn off terminal entry line prefix/header

How do I fix this? I don't want to change my server name I just want to customize the text here (no server name, still shows path/user). Also what's this section of the terminal window called?
The Terminal Entry line prefix is called the shell prompt.
You can generally find the current config by typing
echo $PS1
That returned this for me: [\e]0;\u#^C\w\a]${debian_chroot:+($debian_chroot)}\u#\h:\w\$
So I was able to remove the "#\h" in both locations and get the desired tag.
export PS1="\[\e]0;\u: \w\a\]${debian_chroot:+($debian_chroot)}\u:\w\$ "
leaving me with "root:/kliq$'

How to set emacsclient background as Emacs background?

I've got (in my .emacs)
(set-background-color "#101416")
(set-foreground-color "#f6f3e8")
And I've got 2 bindings:
alias ex='emacsclient -nw'
alias ec='emacsclient -c -a ""'
ex works fine to open client in terminal but when I want to open it as a frame I've got white background :(
Why and how can I use my dark background there?
set-background-color and set-foreground-color only affect the current frame, and your .emacs file is not executed when running emacsclient.
Try setting the variable default-frame-alist ("Alist of default values for frame creation") instead:
(setq default-frame-alist
'((background-color . "#101416")
(foreground-color . "#f6f3e8")))

current directory doesn't appear in title bar when running under screen

My xterm $prompt variable in my .tcshrc is:
set prompt="%{\033]0;%m:%~\007%}%{^[[;37;1m%}%B%{^[[;34;1m%}%m%{^[[;34;1m%}:%b%c%# "
The highlighted part above (%{\033]0;%m:%~\007%}) puts the hostname (%m) and the current directory (%~) in the title bar. (At least I think that that's what puts it in the title bar; it's been a while since I fiddled with this prompt).
When I run screen, however, the current directory stops getting updated when I change directories.
My questions:
How can I make this prompt work in screen?
Is there a better way to display the current directory in the title bar?
I am running linux with xterm and tcsh.
I think there is no direct way, because of the way screen works. However screen can display its own status bar, that you can define in .screenrc. Here's mine for instance :
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%=%{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
Firstly, to make it work you must check where exactly is the line with set prompt=blah-blah in your .tcshrc. For example, the code below that perfectly works in plain xterm would not work under screen in xterm:
switch ($TERM)
case "xterm*":
set prompt="%{\033]0;${HOME:t}#%m:%l:%c08\007%}%{\033[36m%}%l:%c02%#%{\033[0m%} "
# update xterm title to display current cmd in it
alias postcmd 'echo -n "\033]0;${HOME:t}#`hostname`:${tty} \!#:q\007"'
...
because screen by default sets $TERM variable to screen and not xterm! So you must add:
case "screen":
# lame, but prevents an error in screen after 'su - root'
if (! $?WINDOW) setenv WINDOW 1
set prompt="%{\033]0;${HOME:t}#%m:${WINDOW}:%c08\007%}%{\033[36m%}%c02%#%{\033[0m%} "
alias postcmd 'echo -n "\033]0;${HOME:t}#`hostname`:${WINDOW} \!#:q\007"'
...
Secondly, make sure yo have this line in ~/.screenrc:
termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'

Resources