├── .gitattributes
├── .github
└── workflows
│ └── build.yml
├── .gitignore
├── LICENSE
├── Makefile
├── PKGBUILD
├── Pictures
└── terminal.png
├── README.md
├── dollarskip.c
└── install.sh
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.sh linguist-detectable=false
2 |
3 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | # Controls when the action will run.
4 | on:
5 | # Triggers the workflow on push or pull request events but only for the master branch
6 | push:
7 | branches: [ master ]
8 | pull_request:
9 | branches: [ master ]
10 |
11 | # Allows you to run this workflow manually from the Actions tab
12 | workflow_dispatch:
13 |
14 | jobs:
15 | # This workflow contains a single job called "build"
16 | build:
17 | # The type of runner that the job will run on
18 | runs-on: ubuntu-latest
19 |
20 | steps:
21 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
22 | - uses: actions/checkout@v2
23 |
24 | - name: make
25 | run: make
26 |
27 | - name: upload binary
28 | uses: actions/upload-artifact@v2.2.4
29 | with:
30 | name: DollarSkip_build
31 | path: ./dollarskip
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | dollarskip
2 | .vscode
3 |
4 | # PKGBUILD files
5 |
6 | src/
7 | pkg/
8 | 3.*.tar.gz
9 | dollarskip*any.pkg.tar.zst
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 CleanMachine1
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: all clean uninstall install
2 |
3 | CC ?= gcc
4 | STRIP ?= strip
5 | PREFIX ?= /usr/local
6 | CFLAGS += -g -Wall -Wextra -Wpedantic
7 |
8 | all: dollarskip
9 |
10 | install: dollarskip
11 | $(STRIP) dollarskip
12 | install -d '$(DESTDIR)$(PREFIX)/bin'
13 | install -m 755 dollarskip '$(DESTDIR)$(PREFIX)/bin/$$'
14 |
15 | uninstall:
16 | rm -f '$(DESTDIR)$(PREFIX)/bin/$$'
17 |
18 | clean:
19 | rm -f dollarskip
20 |
--------------------------------------------------------------------------------
/PKGBUILD:
--------------------------------------------------------------------------------
1 | pkgname="dollarskip"
2 | pkgver="3.1.3"
3 | pkgrel="1"
4 | source=(https://github.com/CleanMachine1/DollarSkip/archive/v3.1.3.tar.gz)
5 | pkgdesc="Skip the dollar!"
6 | arch=('any')
7 | url="https://github.com/CleanMachine1/DollarSkip"
8 | license=('MIT')
9 | depends=('glibc')
10 | makedepends=('gcc' 'make' 'glibc')
11 | build() {
12 | cd DollarSkip-${pkgver}
13 | make
14 | }
15 |
16 | package() {
17 | cd DollarSkip-${pkgver}
18 | make install DESTDIR="${pkgdir}"
19 | }
20 |
21 | sha256sums=('120ba7642bcef50da5f6644856810c4b13ab00b7e65b093ac84d5772a2a667f6')
22 |
--------------------------------------------------------------------------------
/Pictures/terminal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CleanMachine1/DollarSkip/d11760273a67858c4ba7869f423bd96dd2821c9c/Pictures/terminal.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DollarSkip
2 | 
3 | [](https://github.com/CleanMachine1/DollarSkip/actions/workflows/build.yml)
4 | ## What is DollarSkip
5 |
6 | DollarSkip is a short piece of C code designed to ignore the dollar symbol at the start of commands.
7 |
8 | It aims to solve the annoyance of copying commands and having the annoying error
9 |
10 | `$: command not found`
11 |
12 | ## Installation
13 |
14 | ### 1-Liner install
15 |
16 | __You need to have **wget** installed to run this command__
17 |
18 | To install, run the following command in a terminal:
19 |
20 | ```
21 | wget -qO- https://git.io/JsAqw | bash
22 | ```
23 |
24 | The link is shortened version of https://raw.githubusercontent.com/CleanMachine1/DollarSkip/master/install.sh.
25 |
26 | ### Arch Based
27 |
28 | - https://aur.archlinux.org/packages/dollarskip/
29 |
30 | The package can be installed with an AUR helper such as yay:
31 |
32 | ```
33 | yay -S dollarskip
34 | ```
35 |
36 | ### Other
37 |
38 | __To download and compile DollarSkip you need **Git** (to download the files) and **Make** (to make compilation easier)__
39 |
40 |
41 | To install DollarSkip without Git or Make
42 |
43 | If you don't want to use Git and Make, you can download the zip from [here](https://github.com/CleanMachine1/DollarSkip/archive/refs/heads/master.zip) or you can download the most stable version [here](https://github.com/CleanMachine1/DollarSkip/archive/refs/tags/3.1.zip) and compile `dollarskip.c` with `gcc dollarskip.c -o temp` then move `temp` to `/usr/local/bin/$` with `sudo mv temp /usr/local/bin/\$`.
44 |
45 |
46 |
47 | To install, run the following commands in a terminal:
48 |
49 | ```shell
50 | cd ~/ # Or your place of choice for Git repositories
51 | git clone https://github.com/CleanMachine1/DollarSkip # Or use SSH
52 | cd DollarSkip
53 | make # This makes the binary
54 | sudo make install # This copies the binary to /usr/local/bin and names it '$'
55 | make clean # Removes the binary created above since it has already been moved
56 | ```
57 |
58 | After you can test to see if it works.
59 |
60 | Run the following command, see the output and compare.
61 |
62 | ```shell
63 | $ echo 1
64 | 1
65 | ```
66 |
67 | If you get a different output, please explain your situation and any error messages attached.
68 |
69 | ## Uninstallation
70 |
71 | ```shell
72 | cd ~/DollarSkip # Or where you put the Git directory
73 | sudo make uninstall # Remove the binary in /usr/local/bin/
74 | cd ..
75 | rm -rf ./DollarSkip
76 |
77 | # If the DollarSkip directory doesn't exist, simply run the following command:
78 |
79 | sudo rm /usr/local/bin/\$ # or /usr/bin/\$ (depending on when you installed).
80 | ```
81 |
82 | ## How this works
83 |
84 | DollarSkip makes a binary file called $, in return whenever the first word of a command is $ on its own, Linux see this as a application, since when installing, the $ file is moved to /usr/local/bin/
85 |
86 | It can have side effects and if any occur, just run the uninstallation and tell me what went wrong!
87 |
88 | ## Side Note
89 |
90 | This project was a learning experience for me, since my C needs to improve!
91 |
92 | __I am not responsible for any damage to your system!__
93 | Max character count in a single command is 8000!
94 | Anything over may create a segmentation fault!
95 |
96 | In no event shall:
97 | The authors or copyright holders be liable for any claim, damages or other
98 | liability, whether in an action of contract, tort or otherwise, arising from,
99 | out of or in connection with the software or the use or other dealings in the
100 | software. (MIT license)
101 |
102 | If you decided to run a stupid command which creates a buffer overflow, expect a system crash!
103 |
--------------------------------------------------------------------------------
/dollarskip.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #ifndef COMMAND_MAX_SIZE
7 | #define COMMAND_MAX_SIZE 8096
8 | #endif
9 |
10 | /******
11 | * Collect all the arguments (argv) excluding the first one (argv[0]) into a single string.
12 | * returned string is heap allocated so you have to free() it.
13 | *
14 | * @param argc argc from main()
15 | * @param argv argv from main()
16 | * @param argv_size pointer to an integer. if not NULL, the length of argv + 1 after each argument will be put in it.
17 | *
18 | * @return A heap allocated string containing all of argv excluding argv[0]
19 | ******/
20 | char *collect_args(int argc, char **argv, size_t *argv_size) {
21 | size_t argv_len = 0;
22 | char *args = NULL;
23 |
24 | // get the size of all of argv + a space after each argument (last one for the null terminator)
25 | for(int i = 1; i < argc; ++i) {
26 | argv_len += strlen(argv[i]) + 1; // 1 for the space and null terminator at the end
27 | }
28 | // if argv_size isn't NULL, dereference it and put argv_len in it.
29 | if(argv_size != NULL) *argv_size = argv_len;
30 |
31 | // allocate memory for the argument string
32 | args = malloc(argv_len);
33 | if(args == NULL) exit(1);
34 |
35 | // copy all of argv (exluding argv[0]) to args and add a space after each argument
36 | for(int i = 1; i < argc; ++i) {
37 | strcat(args, argv[i]);
38 | strcat(args, " ");
39 | }
40 | // remove the space at the end
41 | args[argv_len - 1] = '\0';
42 | return args;
43 | }
44 |
45 | int main(int argc, char **argv) {
46 | // if arguments are provided
47 | if(argc > 1) {
48 | char command[COMMAND_MAX_SIZE] = {0};
49 | // get the default system shell
50 | char *shell_env = getenv("SHELL");
51 | // if it exists
52 | if(shell_env != NULL && strcmp(shell_env, "")) {
53 | size_t argv_len = 0;
54 | // collect arguments
55 | char *args = collect_args(argc, argv, &argv_len);
56 | // check that there is enough space in 'command'
57 | assert(argv_len + strlen(shell_env) + 6 < COMMAND_MAX_SIZE); // 6 = strlen(" -c ''")
58 | // and format them
59 | snprintf(command, COMMAND_MAX_SIZE, "%s -c \'%s\'", shell_env, args);
60 | free(args);
61 | } else { // if the default shell doesn't exist
62 | size_t argv_len = 0;
63 | // collect the arguments
64 | char *args = collect_args(argc, argv, &argv_len);
65 | // check that there is enough space in 'command'
66 | assert(argv_len < COMMAND_MAX_SIZE);
67 | // and copy them to the command variable unformatted
68 | strncpy(command, args, COMMAND_MAX_SIZE);
69 | free(args);
70 | }
71 |
72 | // finally run the command
73 | return system(command);
74 | }
75 | // if no arguments provided, do nothing and return 1
76 | return 1;
77 | }
78 |
--------------------------------------------------------------------------------
/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | function error() {
4 | echo -e "\e[1;31m$1\e[0m"
5 | exit 1
6 | }
7 |
8 | #installs the packages provided using the package manager that your system uses
9 | function pkg-install() {
10 | if command -v apt >/dev/null ; then
11 | sudo apt install -y $@
12 | elif command -v pacman >/dev/null ; then
13 | sudo pacman -S --noconfirm $@
14 | else
15 | error "No package manager found! please report this."
16 | fi
17 | }
18 |
19 | # array that will contain all the packages to install
20 | depends=()
21 |
22 | #add the needed packages to the array decalred above if they are not installed
23 | if ! command -v make >/dev/null; then
24 | depends+=("make")
25 | fi
26 |
27 | if ! command -v gcc >/dev/null ; then
28 | depends+=("gcc")
29 | fi
30 |
31 | if ! command -v git >/dev/null; then
32 | depends+=("git")
33 | fi
34 |
35 | # if the array isn't empty, install the packages using the package names it contains and the 'pkg-install' function
36 | if [[ "${depends[@]}" != "" ]]; then
37 | pkg-install ${depends[@]}
38 | fi
39 |
40 | if [[ ! -d DollarSkip ]]; then
41 | git clone https://github.com/CleanMachine1/DollarSkip.git || error "Failed to clone DollarSkip repository!"
42 | cd DollarSkip || error "Failed to enter DollarSkip folder!"
43 | else
44 | cd DollarSkip || error "Failed to enter DollarSkip folder!"
45 | git pull || error "Failed to update repository!"
46 | fi
47 | clear -x
48 | make || error "Failed to run \"make\"!"
49 | sudo make install || error "Failed to run \"sudo make install\"!"
50 | make clean
51 |
52 | echo "If you see 'It Works!', then it works!"
53 | sleep 1
54 | $ echo "It Works!" || error "DollarSkip has failed!"
55 | exit
56 |
--------------------------------------------------------------------------------