aboutsummaryrefslogtreecommitdiff
path: root/mc
blob: 96ec17c4a8267bc24bde560305e54daf02b6b0e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#
# Wrapper for Midnight Commander
#

# Parameters
BASENAME="`basename $0`"
MC="/usr/bin/mc"
INI="$HOME/.config/mc/ini"
CONF="`readlink $INI || echo $INI`"

# Get the current window name
# Thanks http://www.shelldorado.com/scripts/cmds/xtitle
function mc_window_name {
  if [ ! -z "$WINDOWID" ]; then
    xprop -id $WINDOWID | grep ^WM_NAME | sed 's/.*=[         "]*\([^"]*\)["]*$/\1/'
  fi
}

# Dispatch
if [ ! -z "$DISPLAY" ]; then
  WINDOWNAME="`mc_window_name`"
  TERM=xterm-256color $MC $*
  NEWWINDOWNAME="`mc_window_name`"

  # Restore window name as mc forgets to do it
  if [ "$WINDOWNAME" != "$NEWWINDOWNAME" ]; then
    if echo $NEWWINDOWNAME | grep -q '^mc \['; then
      xtitle $WINDOWNAME
    fi
  fi
else
  $MC $*
fi

# Fix configuration
#
# These settings vary from screen size to screen size and
# might change mc's dotfiles whenever it's run on a different
# screen configuration.
#
# If $INI is a link, $CONF will be the link destination.
# That's important because `sed -i` usually breaks the linking.
sed -i '/^left_panel_size=.*$/d' $CONF
sed -i '/^top_panel_size=.*$/d'  $CONF