Skip to content

Commit

Permalink
Register a URL handler for codelite:// (#3387)
Browse files Browse the repository at this point in the history
  • Loading branch information
AJenbo authored Jun 3, 2024
1 parent d34a082 commit 7c26dee
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions LiteEditor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,13 @@ if(NOT APPLE)
FILES ${CL_SRC_ROOT}/Runtime/codelite_xterm
DESTINATION ${CL_INSTALL_BIN}
PERMISSIONS ${EXE_PERM})
install(
FILES ${CL_SRC_ROOT}/Runtime/codelite-url-handler
DESTINATION ${CL_INSTALL_BIN}
PERMISSIONS ${EXE_PERM})
# Create application launcher, copy application icon to standard location
install(FILES ${CL_SRC_ROOT}/Runtime/codelite.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
install(FILES ${CL_SRC_ROOT}/Runtime/codelite-url-handler.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
# Install icons

# 32x32
Expand Down
33 changes: 33 additions & 0 deletions Runtime/codelite-url-handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# CodeLite URL Handler
# codelite://open?url=file://@file&line=@line
# codelite://open?file=@file&line=@line
# codelite://open?url=file://@file:@line
# codelite://open?file=@file:line
#
# @license GPL
# @author Stefan Auditor <[email protected]>

function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }

arg=$(urldecode "${1}")
pattern=".*file(:\/\/|\=)(.*)(:|&line=)(.*)"

# Get the file path.
file=$(echo "${arg}" | sed -r "s/${pattern}/\2/")

# Get the line number.
line=$(echo "${arg}" | sed -r "s/${pattern}/\4/")

# Check if codelite command exist.
if type codelite > /dev/null; then
/usr/bin/env codelite --line "${line}" "${file}" &
fi

if type wmctrl > /dev/null; then
filename=$(basename "$file")
/usr/bin/env wmctrl -i -a $(wmctrl -l | grep "${filename}" | tail -n 1 | cut -d ' ' -f1)
fi

exit 0
6 changes: 6 additions & 0 deletions Runtime/codelite-url-handler.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Desktop Entry]
Name=CodeLite URL Handler
Exec=codelite-url-handler %u
Type=Application
StartupNotify=false
MimeType=x-scheme-handler/codelite;

0 comments on commit 7c26dee

Please sign in to comment.