├── .gitignore ├── .travis-setup.sh ├── .travis.yml ├── Makefile ├── README.md ├── bitbucket-pipelines.yml ├── envthis.c ├── paththis.c └── shortenthis.c /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /.travis-setup.sh: -------------------------------------------------------------------------------- 1 | sudo apt-get -y install git 2 | git clone https://github.com/json-c/json-c.git json-c 3 | cd json-c 4 | bash autogen.sh 5 | ./configure && make && sudo make install 6 | cd .. 7 | pkg-config --cflags --libs json-c 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: required 3 | before_script: 4 | - bash .travis-setup.sh 5 | script: 6 | - make all 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -g 2 | CFLAGS += $(shell pkg-config --cflags json-c) 3 | LDFLAGS += $(shell pkg-config --libs json-c) 4 | LDFLAGS += $(shell pkg-config --libs --cflags libcurl) 5 | all: envthis paththis shortenthis 6 | 7 | envthis: 8 | gcc envthis.c -o envthis $(CFLAGS) 9 | paththis: 10 | gcc paththis.c -o paththis $(CFLAGS) 11 | shortenthis: 12 | gcc shortenthis.c -o shortenthis $(LDFLAGS) $(CFLAGS) 13 | clean: 14 | rm paththis envthis shortenthis 15 | install: 16 | sudo mv paththis /usr/bin/ 17 | sudo mv shortenthis /usr/bin/ 18 | sudo mv envthis /usr/bin/ 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lazy Tools # 2 | [![Build Status](https://travis-ci.org/Kiloreux/lazy_tools.svg?branch=master)](https://travis-ci.org/Kiloreux/lazy_tools) 3 | ------------------------------------------------------------------------------- 4 | 5 | This is a bunch of tools that I have developed due to my super laziness on working with the linux OS, if you think you have an idea for a tool really lazy, open an issue, and I'd be happy to develop the laziest tool every time. 6 | 7 | ## Usage ## 8 | 9 | `envthis VARIABLE_NAME # adds the current path under VARIABLE_NAME` 10 | 11 | `paththis # adds the current path to the $PATH variable` 12 | 13 | `shortenthis https://www.google.com # shortens the URL and give it back to you` 14 | 15 | ##Compiling### 16 | 17 | You should know that, I'm too lazy to tell you. 18 | -------------------------------------------------------------------------------- /bitbucket-pipelines.yml: -------------------------------------------------------------------------------- 1 | pipelines: 2 | default: 3 | - step: 4 | script: 5 | - sudo apt-get update 6 | - sudo apt-get -y install libcurl3 libcurl4-nss-dev 7 | - sudo apt-get -y install dh-autoreconf build-essential 8 | - sudo bash .travis-setup.sh 9 | - make all 10 | -------------------------------------------------------------------------------- /envthis.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | if (argv[1] == NULL ) { 13 | printf("Please enter the variable name as argument\nenvthis HOME\n"); 14 | return(1); 15 | } 16 | char *p = argv[1]; 17 | while (*p != '\0') { 18 | *p = toupper(*p); 19 | p++; 20 | } 21 | 22 | char path[PATH_MAX]; 23 | getcwd(path, PATH_MAX); 24 | struct passwd *user = getpwuid(getuid()); 25 | char* homedir = strcat(user->pw_dir, "/.bashrc"); 26 | 27 | FILE *fp = fopen(homedir, "a"); 28 | fprintf(fp, "%s", strcat(argv[1],"=")); 29 | fprintf(fp, "%s", path); 30 | fprintf(fp, "%s", "\n"); 31 | fclose(fp); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /paththis.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(void) 10 | { 11 | char path[PATH_MAX]; 12 | getcwd(path, PATH_MAX); 13 | struct passwd *user = getpwuid(getuid()); 14 | char *homedir = strcat(user->pw_dir,"/.bashrc"); 15 | FILE *profile; 16 | profile=fopen(homedir, "a"); 17 | fprintf(profile,"%s", "PATH="); 18 | fprintf(profile,"%s", path); 19 | fprintf(profile,"%s", "/:$PATH\n"); 20 | fclose(profile); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /shortenthis.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct string { 9 | char* res; 10 | size_t len; 11 | }; 12 | 13 | void init_string(struct string *s) { 14 | s->len = 0; 15 | s->res = malloc(s->len+1); 16 | if (s->res == NULL) { 17 | fprintf(stderr, "malloc() has failed\n"); 18 | exit(EXIT_FAILURE); 19 | } 20 | s->res[0]='\0'; 21 | } 22 | 23 | 24 | size_t writeOutput(void *ptr, size_t size, size_t nmemb, struct string* s) { 25 | size_t new_len = s->len+size*nmemb; 26 | s->res = realloc(s->res, new_len+1); 27 | if (s->res == NULL) { 28 | fprintf(stderr, "realloc() failed\n"); 29 | exit(EXIT_FAILURE); 30 | } 31 | memcpy(s->res+s->len, ptr, size*nmemb); 32 | s->res[new_len] = '\0'; 33 | s->len = new_len; 34 | return size*nmemb; 35 | } 36 | 37 | int main(int argc, char *argv[]) { 38 | 39 | if (argv[1] == NULL) { 40 | printf("Please enter a URL too be shortened"); 41 | return(1); 42 | } 43 | 44 | struct json_object *req_body,*res_body,*short_url; 45 | struct string res; 46 | init_string(&res); 47 | CURL* handle; 48 | CURLcode rcode; 49 | char *url = "https://www.googleapis.com/urlshortener/v1/url?key=YOUR_API_KEY"; 50 | struct curl_slist *headers = NULL; 51 | 52 | handle = curl_easy_init(); 53 | req_body = json_object_new_object(); 54 | json_object_object_add(req_body, "longUrl", json_object_new_string(argv[1])); 55 | headers = curl_slist_append(headers, "Content-Type: application/json"); 56 | headers = curl_slist_append(headers, "Accept: application/json"); 57 | curl_easy_setopt(handle, CURLOPT_URL, url); 58 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); 59 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); 60 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "POST"); 61 | curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 62 | curl_easy_setopt(handle, CURLOPT_POSTFIELDS, json_object_to_json_string(req_body)); 63 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeOutput); 64 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, &res); 65 | rcode = curl_easy_perform(handle); 66 | if (rcode != CURLE_OK) { 67 | fprintf(stderr, "curl_easy_perform() failed : %s .\n", curl_easy_strerror(rcode)); 68 | } 69 | res_body = json_tokener_parse(res.res); 70 | json_object_object_get_ex(res_body, "id", &short_url); 71 | printf("%s\n", json_object_to_json_string_ext(short_url, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY)); 72 | free(res.res); 73 | curl_easy_cleanup(handle); 74 | json_object_put(res_body); 75 | json_object_put(req_body); 76 | json_object_put(short_url); 77 | return 0; 78 | } 79 | --------------------------------------------------------------------------------