5

I created a file ~/.Xmodmap with my mapping commands. I thought that it will be automatically launched after login (and restart) but it's not. So I have to always run after login the command

$ xmodmap .Xmodmap

Is it possible to automatize this process?

thank you

xralf
  • 15,415
  • Whatever solution you are trying out, use absolute path to your scripts. This worked for me: https://askubuntu.com/a/54194/591187 . – BanAnanas May 15 '20 at 12:54

2 Answers2

3

I was looking through old questions here just last night for this issue. This post suggests putting the xmodmap ~/.Xmodmap line in ~/.xsessionrc and making sure /etc/X11/xsession.options contains the line allow-user-xsession.

I haven't rebooted since then to test it, however.

Wolf
  • 3,045
0

Yes, but exactly how depends on which shell you're using.

In case of bash, edit ~/.bashrc and add a line saying
xmodmap ~/.Xmodmap

If you don't have a ~/.bashrc yet, create one and start it with

#!/bin/bash 
if [ -f /etc/bash.bashrc ] ; then
    . /etc/bash.bashrc
fi 

xmodmap ~/.Xmodmap

If you're using a different login shell such as tcsh or dash or zsh, you'll need to check its manpage to see what files it reads and executes on startup and add the command there. If you're unsure what login shell you're using, the SHELL environment variable should have been set, and you can check that instead with echo $SHELL .

EDIT: My bad. ~/.xsession is the correct file to add this.

  • Additional question for fellow helpers: Given that not all terminal emulators default to a login shell I recommended .bashrc rather than .bash_profile; if there's a persuasive argument for keeping it restricted to login shells I'd like to hear it. – Shadur-don't-feed-the-AI Apr 19 '11 at 07:36
  • I'm using bash. Maybe I asked the question bad way. I edited ~/.bashrc as you said and restarted the computer and after restart I had to run xmodmap ~/.Xmodmap manually to have remapped keys. – xralf Apr 19 '11 at 08:12
  • Try adding the line to ~/.bash_profile as well, as ~/.bashrc may not get loaded in a login shell. – Shadur-don't-feed-the-AI Apr 19 '11 at 09:07
  • This helped. I had to create the file ~/.bash_profile . Should I add all the lines or only the one line with xmodmap ~/.Xmodmap? – xralf Apr 19 '11 at 09:37
  • This worked for a while but stopped working and I had to run it manually again. – xralf Apr 19 '11 at 09:50
  • .bashrc is aboslutely not the right place. It is read when you start an interactive shell. It is not read when you start a graphical environment, but it will be read each time you open a terminal window. In other words, it won't trigger when it should, and will trigger when it shouldn't. – Gilles 'SO- stop being evil' Apr 19 '11 at 20:12
  • My bad. Which is, then? .xsession? – Shadur-don't-feed-the-AI Apr 19 '11 at 20:29
  • @Shadur: Should it be .xsession or .xsessionrc? The one I linked to mentions both. – Wolf Apr 20 '11 at 00:43
  • According to http://www.acm.uiuc.edu/workshops/cool_unix/xinitrc.html it's either .xinitrc or .xsession depending on how you start X -- if you use gdm or kdm or the like, it's the latter, if you use startx from the command line it's the former. – Shadur-don't-feed-the-AI Apr 20 '11 at 06:41
  • $ ps aux | grep X root 619 1.7 1.1 30772 22908 tty7 Ss+ 07:50 0:34 /usr/bin/X :0 -br -verbose -auth /var/run/gdm/auth-for-gdm-WDyyFH/database -nolisten tcp vt7 xralf 946 0.0 0.0 1832 536 ? Ss 07:51 0:00 /bin/sh /etc/xdg/xfce4/xinitrc -- /etc/X11/xinit/xserverrc xralf 1073 0.0 0.5 50228 12244 ? S 07:51 0:00 /usr/lib/xfce4/panel-plugins/xfce4-menu-plugin socket_id 27263015 name xfce4-menu id 1 display_name Xfce Menu size 24 screen_position 11 so, I think I'm using startx? Should I create the file ~/.xinitrc? – xralf Apr 21 '11 at 06:26
  • From the looks of it, you're using gdm. Like I said, the easy way to check is whether you use a graphical login screen or whether you start with a command prompt -- and if you have to ask, you're likely using gdm. So .xsession – Shadur-don't-feed-the-AI Apr 21 '11 at 07:29
  • OK, I pasted the row into .xsession. I will give it few days time. thank you – xralf Apr 21 '11 at 09:08