-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathxmap.sh
More file actions
executable file
·82 lines (73 loc) · 2.04 KB
/
xmap.sh
File metadata and controls
executable file
·82 lines (73 loc) · 2.04 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
########################################################################
# xmap.sh: Apply ~/.Xmodmap using xmodmap if available
#
# Description:
# Load user's $HOME/.Xmodmap with xmodmap when both the command and the
# file are available.
#
# Author: id774 (More info: http://id774.net)
# Source Code: https://github.com/id774/scripts
# License: The GPL version 3, or LGPL version 3 (Dual License).
# Contact: idnanashi@gmail.com
#
# Usage:
# xmap.sh
#
# Requirements:
# - xmodmap(1) installed
#
# Options:
# -h, --help Show this help (prints the header block)
# -v, --version Show the version (prints the header block)
#
# Version History:
# v1.0 2025-09-05
# Initial release.
#
########################################################################
# Display full script header information extracted from the top comment block
usage() {
awk '
BEGIN { in_header = 0 }
/^#{10,}$/ { if (!in_header) { in_header = 1; next } else exit }
in_header && /^# ?/ { print substr($0, 3) }
' "$0"
exit 0
}
# Check if required commands are available and executable
check_commands() {
for cmd in "$@"; do
cmd_path=$(command -v "$cmd" 2>/dev/null)
if [ -z "$cmd_path" ]; then
echo "[ERROR] Command '$cmd' is not installed. Please install $cmd and try again." >&2
exit 127
elif [ ! -x "$cmd_path" ]; then
echo "[ERROR] Command '$cmd' is not executable. Please check the permissions." >&2
exit 126
fi
done
}
# Apply ~/.Xmodmap (assumes xmodmap exists)
apply_xmodmap() {
file="$HOME/.Xmodmap"
if [ ! -f "$file" ]; then
echo "[INFO] ~/.Xmodmap not found; skipped."
return 2
fi
echo "[INFO] Applying $file..."
xmodmap -verbose "$file"
return $?
}
# Main entry point of the script
main() {
case "$1" in
-h|--help|-v|--version) usage ;;
esac
check_commands xmodmap
# Apply if file exists
apply_xmodmap
return $?
}
# Execute main function
main "$@"