Xit0

Random Scribblings of a Linux Enthusiast

Web Server From Any Directory in Linux

If you want to quickly test a website under development or serve a couple of webpages from a local directory without the hassle of moving/linking the directory to a web server root, the following python command helps:

Remove Redundant /blog Prefix From Octopress Website

Octopress, by default, generates static websites with a /blog prefix attached to categories, archives and post URLs. This is particularly annoying when the blog is hosted at blog.yourdomain.tld and have funny URLs like blog.yourdomain.tld/blog/archives.

To get rid of this, I’ve created a clone of the classic Octopress theme with the necessary changes. It also renames Blog to Home in the navigation bar.

CMake: Use Git Branch & Commit Details in Project

To use git branch and commit hash information in a CMake project, add the following lines to CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Get the current working branch
execute_process(
  COMMAND git rev-parse --abbrev-ref HEAD
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  OUTPUT_VARIABLE GIT_BRANCH
  OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the latest abbreviated commit hash of the working branch
execute_process(
  COMMAND git log -1 --format=%h
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  OUTPUT_VARIABLE GIT_COMMIT_HASH
  OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process() runs a single command or a sequence of commands and optionally gathers the output into CMake variables. The COMMAND is executed in WORKING_DIRECTORY and the STDOUT is saved to OUTPUT_VARIABLE after stripping trailing whitespace. The output of git log can be customized.