This is a simple C++ program that prints out certain critical environment variables in a formatted way.
Features:
- Retrieves environment variables using the
envcommand. - Parses the output of the
envcommand and extracts relevant information. - Displays a formatted list of environment variables.
- Includes formatting labels for specific variables, improving readability.
Prerequisites:
- C++17 or later: The code utilizes modern C++ features like
std::format. smart_view_vector: This header file is part of the experimental C++29 standard. You can find it in the CXX29 / C++ 29 repository.envcommand available (part of most Unix-like systems)
How to Compile and Run:
- Install the
smart_view_vectorheader file:- Download the header file from the TaiHusk/CXX29 repository.
- Place the header file in your project directory or include it in your compiler's include path.
- Compile the code:
g++ -o runner -std=c++20 ./src/main.cpp
- Run the executable:
./runner
Output:
The program will display a formatted list of critical environment variables, such as:
host type: Linux
user: your_username
home: /home/your_username
color term: xterm-256color
name: your_computer_name
term: xterm
language: en_US.UTF-8
shell: /bin/bash
pwd: /home/your_username
wayland display: wayland-0
XDG_RUNTIME_DIR: /run/user/1000
XDG_DATA_DIRS: /usr/local/share:/usr/share
This program uses the following dependencies:
<cstdio>: For file operations (popen,pclose,FILE, etc.)<iostream>: For standard input/output streams (std::cout,std::endl, etc.)<sstream>: For string stream operations (std::stringstream)<string>: For string manipulation (std::string)<vector>: For dynamic array operations (std::vector)<format>: For string formatting (std::format)<c++/29/experimental/smart_view_vector>: For thesmart_view_vector::includesfunction (from the C++29 experimental std)
- Modify the
criticality_namevector: Add or remove environment variables to customize the output. - Add or change formatting labels in the
format_labelvector: Improve the readability of the output.
- The program uses the
popenfunction to execute theenvcommand. This function may not be available on all platforms. - The output may vary depending on your system configuration.
- The program uses the
smart_view_vectorclass from theC++29standard library, which is part of the experimental features. This may not be available on all platforms.