aboutsummaryrefslogtreecommitdiff
path: root/mc
blob: 228abc50bc1f1a922cfca6b1a301012832d7edf7 (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
46
47
48
49
50
51
52
53
54
55
56
57
#!/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.

# Delete left_panel_size config
if grep -q "^left_panel_size=.*$" $CONF; then
  #sed -i '/^left_panel_size=.*$/,+1 d' $CONF
  sed -i '/^left_panel_size=.*$/ d' $CONF
fi

# Delete top_panel_size config and the following blank line
if grep -q "^top_panel_size=.*$" $CONF; then
  sed -i '/^top_panel_size=.*$/,+1 d'  $CONF
fi

# Delete all empty lines from config
#sed -i '/^$/d' $CONF